-
Notifications
You must be signed in to change notification settings - Fork 0
/
exampleUseSpec.js
166 lines (153 loc) · 6.66 KB
/
exampleUseSpec.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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
var expect = require("chai").expect;
var request = require('superagent');
const agent = request.agent();
var adminUsername = "[email protected]";
var adminPass = "admin123";
var authToken='';
var url = "http://127.0.0.1:3000";
function getRandomInt(max) {
return Math.floor(Math.random() * Math.floor(max));
}
describe("Exercise Administrator Authenticated Use Cases", function() {
beforeEach(function(done) {
this.timeout(10000)
agent
.post(url + '/rest/user/login')
.set('Content-Type', 'application/json;charset=utf-8')
.send({email: adminUsername, password: adminPass})
.end(function(error, response){
expect(response.status).to.equal(200);
authToken = response.body['authentication']['token'];
agent.set('Authorization','Bearer ' + authToken)
agent.set('Cookie','token=' + authToken)
done();
});
});
it("Administrators may view email addresses for all users", function(done) {
this.timeout(10000)
//create user account
var tmpAgent = request.agent();
var testEmail = "derpy" + getRandomInt(10000) + "@mcfuggles.local"
var postData = "{\"email\":\"" + testEmail + "\",\"password\":\"password1\",\"passwordRepeat\":\"password1\",\"securityQuestion\":{\"id\":2,\"question\":\"Mother's maiden name?\",\"createdAt\":\"2018-01-10T03:27:48.409Z\",\"updatedAt\":\"2018-01-10T03:27:48.409Z\"},\"securityAnswer\":\"test\"}"
tmpAgent
.post(url+'/api/Users/')
.set('Content-Type', 'application/json;charset=utf-8')
.send(postData)
.end(function(error, response, body) {
expect(response.status).to.equal(201);
agent.get(url+'/rest/user/authentication-details/', function(error, response, body) {
expect(response.status).to.equal(200);
expect(JSON.stringify(response.body)).to.contain('"email":"' + testEmail + '"');
done();
});
});
});
it("Authenticated adding shopping cart quantity 2", function(done) {
this.timeout(4000)
agent
.post(url+'/api/BasketItems/')
.set('Content-Type', 'application/json;charset=utf-8')
.send({"ProductId":5,"BasketId":"1","quantity":2})
.end(function(error, response, body) {
expect(response.status).to.equal(201)
agent
.post(url+'/rest/basket/1/checkout')
.set('Content-Type', 'application/json;charset=utf-8')
.send()
.end(function(error, response, body) {
expect(response.status).to.equal(200)
done();
});
});
});
it("Authenticated users may leave feedback", function(done) {
var tmpAgent = request.agent();
tmpAgent
.set('Content-Type', 'application/json;charset=utf-8')
.get(url+'/rest/captcha/', function(error, response, body) {
expect(response.status).to.equal(200);
var captchaid=response.body['captchaId'];
var captchaanswer=response.body['answer'];
agent
.post(url+'/api/Feedbacks/')
.set('Content-Type', 'application/json;charset=utf-8')
.send({"UserId":1,"rating":5,"comment":"test","captcha":captchaanswer,"captchaId":captchaid})
.end(function(error, response, body) {
expect(response.status).to.equal(201)
done();
});
});
});
it("Administrators may modify product descriptions.", function(done) {
this.timeout(10000)
agent
.put(url+'/api/Products/1')
.set('Content-Type', 'application/json;charset=utf-8')
.send({"description":"The all-time classic."})
.end(function(error, response, body) {
expect(response.status).to.equal(200)
done();
});
});
it("Users may check the contents of their own shopping cart.", function(done) {
agent.get(url+'/rest/basket/1', function(error, response, body) {
expect(response.status).to.equal(200);
done();
});
});
});
describe("Exercise Unauthenticated Use Cases", function() {
it("Unauthenticated users may leave feedback with ratings between 1 and 5 (max).", function(done) {
var tmpAgent = request.agent();
tmpAgent
.set('Content-Type', 'application/json;charset=utf-8')
.get(url+'/rest/captcha/', function(error, response, body) {
expect(response.status).to.equal(200);
var captchaid=response.body['captchaId'];
var captchaanswer=response.body['answer'];
agent
.post(url+'/api/Feedbacks/')
.set('Content-Type', 'application/json;charset=utf-8')
.send({"rating":5,"comment":"test","captcha":captchaanswer,"captchaId":captchaid})
.end(function(error, response, body) {
expect(response.status).to.equal(201)
done();
});
});
});
it("Unauthenticated users may leave feedback with ratings between 1 and 5 (min).", function(done) {
var tmpAgent = request.agent();
tmpAgent
.set('Content-Type', 'application/json;charset=utf-8')
.get(url+'/rest/captcha/', function(error, response, body) {
expect(response.status).to.equal(200);
var captchaid=response.body['captchaId'];
var captchaanswer=response.body['answer'];
agent
.post(url+'/api/Feedbacks/')
.set('Content-Type', 'application/json;charset=utf-8')
.send({"rating":1,"comment":"test","captcha":captchaanswer,"captchaId":captchaid})
.end(function(error, response, body) {
expect(response.status).to.equal(201)
done();
});
});
});
it("Unauthenticated users may read product information", function(done) {
request.get(url+'/api/Products/1', function(error, response, body) {
expect(response.status).to.equal(200)
done();
});
});
it("Unauthenticated users may upload pdfs < 100k in size", function(done) {
var tmpAgent = request.agent();
tmpAgent
.post(url+'/file-upload')
.set('Content-Type', 'multipart/form-data; boundary=---------------------------87801712517658189031084039755')
.send('-----------------------------87801712517658189031084039755\r\nContent-Disposition: form-data; name="file";filename="test.pdf"\r\nContent-Type: application/pdf\r\n\r\nderp\r\n\r\n-----------------------------87801712517658189031084039755--')
.end(function(error, response, body) {
expect(response.status).to.equal(204)
done();
});
});
});