-
Notifications
You must be signed in to change notification settings - Fork 0
/
3-assert-step-test.js
63 lines (47 loc) · 2.09 KB
/
3-assert-step-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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import makeFavouriteCoffee from 'lightning/utilities/coffee-maker';
import { module, test } from 'qunit';
import Pretender from 'pretender';
const headers = { 'content-type': 'application/json' };
module('Integration | Utility | coffee maker', function() {
module('3. Using assert.step()/assert.verifySteps()', function(hooks) {
let server;
hooks.afterEach(function() {
if (server) {
server.shutdown();
}
});
test('The API calls are made in the correct order', async function(assert) {
const userName = 'Francesca';
const favouriteBeverage = 'cappuccino';
const expectedBeanVariety = 'regular espresso roast';
const expectedServings = 1;
const expectedMessage = 'Your coffee is ready!';
server = new Pretender(function() {
this.get('https://cloud-coffee-service.example.com/user-prefs', request => {
assert.step('user-prefs GET');
assert.equal(request.queryParams.userName, userName, 'Made user-prefs call with correct userName');
return [200, headers, JSON.stringify({ favouriteBeverage })];
});
this.post('https://bean-market.example.com/buy-beans', request => {
assert.step('buy-beans POST');
assert.deepEqual(JSON.parse(request.requestBody), {
beanVariety: expectedBeanVariety,
servings: expectedServings,
}, 'Made buy-beans call with correct body');
return [204];
});
this.post('https://iot-coffee-machine.example.com/brew', request => {
assert.step('brew POST');
assert.deepEqual(JSON.parse(request.requestBody), {
beverageName: favouriteBeverage,
beanVariety: expectedBeanVariety,
}, 'Made brew call with correct body');
return [201, headers, JSON.stringify({ message: expectedMessage })];
});
});
const message = await makeFavouriteCoffee(userName);
assert.equal(message, expectedMessage, 'Returned the correct message');
assert.verifySteps(['user-prefs GET', 'buy-beans POST', 'brew POST']);
});
});
});