forked from juice-shop/juice-shop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deliveryApiSpec.ts
131 lines (120 loc) · 4.23 KB
/
deliveryApiSpec.ts
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
* Copyright (c) 2014-2022 Bjoern Kimminich & the OWASP Juice Shop contributors.
* SPDX-License-Identifier: MIT
*/
import frisby = require('frisby')
const config = require('config')
const API_URL = 'https://localhost:3000/api'
const REST_URL = 'https://localhost:3000/rest'
const jsonHeader = { 'content-type': 'application/json' }
let authHeader: { Authorization: string, 'content-type': string }
describe('/api/Deliverys', () => {
describe('for regular customer', () => {
beforeAll(() => {
return frisby.post(REST_URL + '/user/login', {
headers: jsonHeader,
body: {
email: 'jim@' + config.get('application.domain'),
password: 'ncc-1701'
}
})
.expect('status', 200)
.then(({ json }) => {
authHeader = { Authorization: 'Bearer ' + json.authentication.token, 'content-type': 'application/json' }
})
})
it('GET delivery methods', () => {
return frisby.get(API_URL + '/Deliverys', { headers: authHeader })
.expect('status', 200)
.expect('header', 'content-type', /application\/json/)
.then(({ json }) => {
expect(json.data.length).toBe(3)
expect(json.data[0].id).toBe(1)
expect(json.data[0].name).toBe('One Day Delivery')
expect(json.data[0].price).toBe(0.99)
expect(json.data[0].eta).toBe(1)
})
})
})
describe('for deluxe customer', () => {
beforeAll(() => {
return frisby.post(REST_URL + '/user/login', {
headers: jsonHeader,
body: {
email: 'ciso@' + config.get('application.domain'),
password: 'mDLx?94T~1CfVfZMzw@sJ9f?s3L6lbMqE70FfI8^54jbNikY5fymx7c!YbJb'
}
})
.expect('status', 200)
.then(({ json }) => {
authHeader = { Authorization: 'Bearer ' + json.authentication.token, 'content-type': 'application/json' }
})
})
it('GET delivery methods', () => {
return frisby.get(API_URL + '/Deliverys', { headers: authHeader })
.expect('status', 200)
.expect('header', 'content-type', /application\/json/)
.then(({ json }) => {
expect(json.data.length).toBe(3)
expect(json.data[0].id).toBe(1)
expect(json.data[0].name).toBe('One Day Delivery')
expect(json.data[0].price).toBe(0.5)
expect(json.data[0].eta).toBe(1)
})
})
})
})
describe('/api/Deliverys/:id', () => {
describe('for regular customer', () => {
beforeAll(() => {
return frisby.post(REST_URL + '/user/login', {
headers: jsonHeader,
body: {
email: 'jim@' + config.get('application.domain'),
password: 'ncc-1701'
}
})
.expect('status', 200)
.then(({ json }) => {
authHeader = { Authorization: 'Bearer ' + json.authentication.token, 'content-type': 'application/json' }
})
})
it('GET delivery method', () => {
return frisby.get(API_URL + '/Deliverys/2', { headers: authHeader })
.expect('status', 200)
.expect('header', 'content-type', /application\/json/)
.then(({ json }) => {
expect(json.data.id).toBe(2)
expect(json.data.name).toBe('Fast Delivery')
expect(json.data.price).toBe(0.5)
expect(json.data.eta).toBe(3)
})
})
})
describe('for deluxe customer', () => {
beforeAll(() => {
return frisby.post(REST_URL + '/user/login', {
headers: jsonHeader,
body: {
email: 'ciso@' + config.get('application.domain'),
password: 'mDLx?94T~1CfVfZMzw@sJ9f?s3L6lbMqE70FfI8^54jbNikY5fymx7c!YbJb'
}
})
.expect('status', 200)
.then(({ json }) => {
authHeader = { Authorization: 'Bearer ' + json.authentication.token, 'content-type': 'application/json' }
})
})
it('GET delivery method', () => {
return frisby.get(API_URL + '/Deliverys/2', { headers: authHeader })
.expect('status', 200)
.expect('header', 'content-type', /application\/json/)
.then(({ json }) => {
expect(json.data.id).toBe(2)
expect(json.data.name).toBe('Fast Delivery')
expect(json.data.price).toBe(0)
expect(json.data.eta).toBe(3)
})
})
})
})