forked from stargate/stargate-mongoose-sample-apps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmoke-test.js
42 lines (35 loc) · 1.04 KB
/
smoke-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'use strict';
const assert = require('assert');
const axios = require('axios');
const baseUrl = 'http://127.0.0.1:8888/.netlify/functions';
void async function main() {
const products = await axios.get(`${baseUrl}/getProducts`).then(res => res.data);
assert.ok(Array.isArray(products));
assert.ok(products.length > 0);
let cart = await axios.
put(
`${baseUrl}/addToCart`, {
items: [{ productId: products[0]._id, quantity: 2 }]
}
).
then(res => res.data);
assert.ok(cart);
assert.equal(cart.items.length, 1);
assert.deepStrictEqual(cart.items, [{
productId: products[0]._id.toString(), quantity: 2
}]);
cart = await axios.
put(
`${baseUrl}/addToCart`, {
cartId: cart._id,
items: [{ productId: products[0]._id, quantity: 1 }]
}
).
then(res => res.data);
assert.ok(cart);
assert.equal(cart.items.length, 1);
assert.deepStrictEqual(cart.items, [{
productId: products[0]._id.toString(), quantity: 3
}]);
console.log('Successfully created cart', cart);
}();