Skip to content
This repository was archived by the owner on Dec 5, 2023. It is now read-only.

Commit fbd6bf2

Browse files
author
Aleksandr Guljajev
committed
Better hooks; adding more endpoints
1 parent b491d8e commit fbd6bf2

File tree

4 files changed

+470
-100
lines changed

4 files changed

+470
-100
lines changed

api-spec/hooks.js

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -56,39 +56,42 @@ hooks.afterAll((transactions, done) => {
5656
});
5757

5858
hooks.beforeEach((transaction, done) => {
59-
var promisesToKeep = [
60-
db.collection('customer').remove({}),
61-
db.collection('customer').insertMany(customer),
62-
db.collection('card').remove({}),
63-
db.collection('card').insertMany(card),
64-
db.collection('cart').remove({}),
65-
db.collection('cart').insertMany(cart),
66-
db.collection('address').remove({}),
67-
db.collection('address').insertMany(address),
68-
db.collection('item').remove({}),
69-
db.collection('item').insertMany(item)
70-
];
71-
Promise.all(promisesToKeep).then(function(vls) {
72-
done();
73-
}, function(vls) {
74-
console.error(vls);
75-
done();
76-
});
59+
db.dropDatabase(function(s, r) {
60+
var promisesToKeep = [
61+
db.collection('customer').insertMany(customer),
62+
db.collection('card').insertMany(card),
63+
db.collection('cart').insertMany(cart),
64+
db.collection('address').insertMany(address),
65+
db.collection('item').insertMany(item)
66+
];
67+
Promise.all(promisesToKeep).then(function(vls) {
68+
done();
69+
}, function(vls) {
70+
console.error(vls);
71+
done();
72+
});
73+
})
74+
7775
});
7876

7977

8078
hooks.before("/orders > POST", function(transaction, done) {
81-
transaction.skip = true;
8279
transaction.request.headers['Content-Type'] = 'application/json';
8380
transaction.request.body = JSON.stringify(
8481
{
85-
"customer":"http://accounts/customers/579f21ae98684924944651bd",
86-
"address": "http://accounts/addresses/579f21ae98684924944651bd",
87-
"card" : "http://accounts/cards/579f21ae98684924944651bf",
88-
"items": "http://accounts/items/"
82+
"customer":"http://accounts-orders-mock:80/customers/57a98d98e4b00679b4a830af",
83+
"address": "http://accounts-orders-mock:80/addresses/57a98d98e4b00679b4a830ad",
84+
"card" : "http://accounts-orders-mock:80/cards/57a98d98e4b00679b4a830ae",
85+
"items": "http://accounts-orders-mock:80/carts/579f21ae98684924944651bf/items"
8986
}
9087
);
9188

9289
done()
9390

9491
});
92+
93+
hooks.before("/orders > GET", function(transaction, done) {
94+
transaction.request.headers["User-Agent"] = "curl/7.43.0";
95+
transaction.request.headers["Accept"] = "*/*";
96+
done();
97+
})

0 commit comments

Comments
 (0)