-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
145 lines (126 loc) · 3.62 KB
/
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
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
const axios = require ('axios')
const BASE_URL ="http://localhost:3000"
axios.defaults.baseURL = BASE_URL
const {PATHS} = require("./server.js")
const parsers = require("./parsers.js")
const { LOGIN, PASSWORD, PRIVATE_KEY } = require("./consts.js")
test("Info endpoint positive test", async() => {
const response = await axios.get(PATHS.INFO)
expect(response.status).toEqual(200)
expect(response.data).toEqual('author:23618')
})
test("Hello endpoint positive test", async() => {
try {
await axios.get(PATHS.HELLO+"/Anita")
} catch({response}) {
expect (response.status).toEqual(200)
expect (response.data).toEqual("Name is not valid")
}
})
test("Hello endpoint positive test (whitespace)", async() => {
try {
await axios.get(PATHS.HELLO+"/anita ")
} catch({response}) {
expect (response.status).toEqual(200)
expect (response.data).toEqual("Hello Anita!")
}
})
test("Hello endpoint negative test (name too long)", async() => {
try {
await axios.get(PATHS.HELLO+"/tooooolonggggggggg")
} catch ({response }) {
expect (response.status).toEqual(400)
expect (response.data).toEqual("Name is not valid")
}
})
test("Hello endpoint negative test (used numbers)", async() => {
try {
await axios.get(PATHS.HELLO+"/1234")
} catch ({response}) {
expect (response.status).toEqual(400)
expect (response.data).toEqual("Name is not valid")
}
})
test("Hello endpoint negative test(polish letters used)", async() => {
try {
await axios.get(PATHS.HELLO+"/źćąęń")
} catch ({response}) {
expect (response.status).toEqual(400)
expect (response.data).toEqual("Name is not valid")
}
})
test("Store endpoint positive test(first req)", async () => {
try {
await axios.post(PATHS.STORE, {headers: { 'input': 'value'}})
} catch ({response}) {
expect(response.data).toEqual({
"stored_data": [
"testowa wartość",
]
})
}
})
test("Store endpoint positive test(sec req)", async () => {
try {
await axios.post(PATHS.STORE, {headers: { 'input': 'value'}})
} catch ({response}) {
expect(response.data).toEqual({
"stored_data": [
"testowa wartość",
"testowa wartość"
]
})
}
})
test("Parse positive test", async () => {
const data = "value_A:1;value_B:2;value_C:value_D:3,value_E:4;value_F:5;value_G:value_H:6\n"
const result = parsers.parse(data)
expect(result).toEqual({
value_A: 1,
value_B: 2,
value_C: { value_D: 3, value_E: 4 },
value_F: 5,
value_G: { value_H: 6 },
})
})
test("Login endpoint positive test(string!=NULL)", async () => {
const data = { login: "test", password: "12341234" }
try {
await axios.post(PATHS.LOGIN, data)
} catch ({response}) {
expect (response.value).to.not.equal(null)
expect (response.status).toEqual(200)
expect (response.data).toEqual("Name is not valid")
}
})
test("Hello endpoint negative test (valid login)", async() => {
const data = { login: "testt", password: "12341234" }
try {
await axios.post(PATHS.LOGIN, data)
} catch ({response }) {
expect (response.status).toEqual(401)
expect (response.data).toEqual("Invalid login data")
}
})
test("Hello endpoint negative test (valid password)", async() => {
const data = { login: "test", password: "123412341" }
try {
await axios.post(PATHS.LOGIN, data)
} catch ({response }) {
expect (response.status).toEqual(401)
expect (response.data).toEqual("Invalid login data")
}
})
test("working token", async () => {
const jwt = require('jsonwebtoken')
var token = jwt.sign ( { LOGIN }, PRIVATE_KEY)
const bearer = "Bearer "+token
try {
await axios.get(PATHS.PROFILE, {headers: { 'Authorization': bearer }})
} catch ({response}) {
expect (response.status).toEqual(200)
expect (response.data).toEqual({
"login": "test"
})
}
})