-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestapi.js
160 lines (149 loc) · 5.84 KB
/
testapi.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
//import library:
var should = require('chai').should(),
Expect = require('chai').expect,
Supertest = require('supertest');
//Constants and Data:
const request = require('supertest')
const {expect} = require('chai')
const baseUrl = 'https://kasir-api.belajarqa.com'
const testData = {
"name": "Thetamax93 Store",
"email": "[email protected]",
"password": "bukanpassword"
}
//Test Cases:
//Authorization - Registration (Create):
describe ('Authorization - Registration (Positive)', function(){
const response = request(baseUrl)
.post ('/registration')
.send (testData)
it('response status equal to 201', async () => {
expect((await response).status).to.equal(201)
})
it('status is showing success', async () => {
expect((await response).body.status).to.equal("success")
})
it('data is equal to registered name and email', async () => {
expect((await response).body.data.name).to.equal(testData.name)
expect((await response).body.data.email).to.equal(testData.email)
})
})
describe ('Authorization - Registration no password inputted (Negative)', function(){
const response = request(baseUrl)
.post ('/registration')
.send ({
"name": "Thetamax93 Store",
"email": "[email protected]",
"password": ""
})
it('response status equal to 400', async () => {
expect((await response).status).to.equal(400)
})
it('status is showing fail', async () => {
expect((await response).body.status).to.equal("fail")
})
})
//Authorization - Refresh Token (Update):
//Data:
const testLogin = {
"email": "[email protected]",
"password": "bukanpassword"
}
//Obtain Token:
describe ('Login User', function (){
const response = request(baseUrl)
.post('/authentications')
.send(testLogin)
it('showing the refresh token', async () => {
console.log('refresh token: ' + (await response).body.data.refreshToken)
})
const refToken = (console.log)
//Test Cases:
describe ('Authorization - Refresh Token (Positive)', function() {
const response = request(baseUrl)
.put ('/authentications')
.send ({
"refreshToken" : "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjAzMDVhNTZmLTA0NDQtNDE0Yi1iNDNlLTkzMTA2YzRlNDM5MSIsImNvbXBhbnlJZCI6IjEyYTQ3ZDAyLWU5MmMtNDQ4OC1iYzFmLWZmMTM4MWRjYTY3MCIsImlhdCI6MTY3NTk1MDcyM30.Zlt6nUhsmj0dzMlHf_pOGtIq1EUlOqk8kFcOYwKgoow"
})
it('response status equal to 200', async () => {
expect((await response).status).to.equal(200)
})
it('status is showing success', async () => {
expect((await response).body.status).to.equal("success")
})
it('showing the new access token', async () => {
console.log('access token: ' + (await response).body.data.accessToken)
})
})
describe ('Authorization - Refresh Token (Negative)', function() {
const response = request(baseUrl)
.put ('/authentications')
.send ({
"refreshToken" : "mbak sri"
})
it('response status equal to 400', async () => {
expect((await response).status).to.equal(400)
})
it('status is showing fail', async () => {
expect((await response).body.status).to.equal("fail")
})
})
})
//Users - Get User Detail (Get)
const userId = '0305a56f-0444-414b-b43e-93106c4e4391'
const accToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjAzMDVhNTZmLTA0NDQtNDE0Yi1iNDNlLTkzMTA2YzRlNDM5MSIsImNvbXBhbnlJZCI6IjEyYTQ3ZDAyLWU5MmMtNDQ4OC1iYzFmLWZmMTM4MWRjYTY3MCIsImlhdCI6MTY3NTk0OTI5MX0.kgbundWCSR4XacaTAcGNGu6P9jeH4DBz1Wcb0bwrELk'
//Test Cases:
describe ('Users - Get User Detail (Positive)', function(){
const response = request(baseUrl)
.get ('/users/' + (userId))
.set({
"Authorization": `Bearer ${accToken}`
})
it('response status equal to 200', async () => {
expect((await response).status).to.equal(200)
})
it('status is showing success', async () => {
expect((await response).body.status).to.equal("success")
})
it('data is equal to registered name and email', async () => {
expect((await response).body.data.user.name).to.equal(testData.name)
expect((await response).body.data.user.email).to.equal(testData.email)
})
})
describe ('Users - Get User Detail (Negative)', function(){
const response = request(baseUrl)
.get ('/users/123456')
it('response status equal to 401', async () => {
expect((await response).status).to.equal(401)
})
it('status is showing error "Unauthorized"', async () => {
expect((await response).body.error).to.equal("Unauthorized")
})
})
//Authorization - LogOut (Delete):
describe ('Authorization - Logout (Positive)', function() {
const response = request(baseUrl)
.del ('/authentications')
.send ({
"refreshToken" : "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjAzMDVhNTZmLTA0NDQtNDE0Yi1iNDNlLTkzMTA2YzRlNDM5MSIsImNvbXBhbnlJZCI6IjEyYTQ3ZDAyLWU5MmMtNDQ4OC1iYzFmLWZmMTM4MWRjYTY3MCIsImlhdCI6MTY3NTk1MDcyM30.Zlt6nUhsmj0dzMlHf_pOGtIq1EUlOqk8kFcOYwKgoow"
})
it('response status equal to 200', async () => {
expect((await response).status).to.equal(200)
})
it('status is showing success', async () => {
expect((await response).body.status).to.equal("success")
})
})
describe ('Authorization - Logout (Negative)', function() {
const response = request(baseUrl)
.put ('/authentications')
.send ({
"refreshToken" : "mbak sri"
})
it('response status equal to 400', async () => {
expect((await response).status).to.equal(400)
})
it('status is showing fail', async () => {
expect((await response).body.status).to.equal("fail")
})
})