Skip to content

Commit 518656c

Browse files
kobenguyentDavertMik
authored and
DavertMik
committed
fix: remove mock server helper (#4536)
* ˛fix: remove mock server helper * ˛fix: remove mock server helper * fix: remov pactum lib
1 parent 418514c commit 518656c

File tree

3 files changed

+0
-358
lines changed

3 files changed

+0
-358
lines changed

lib/helper/MockServer.js

-221
This file was deleted.

package.json

-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
"test:unit:webbapi:webDriver:noSeleniumServer": "mocha test/helper/WebDriver.noSeleniumServer_test.js",
5757
"test:unit:webbapi:webDriver:devtools": "mocha test/helper/WebDriver_devtools_test.js --exit",
5858
"test:unit:webbapi:testCafe": "mocha test/helper/TestCafe_test.js",
59-
"test:unit:mockServer": "mocha test/helper/MockServer_test.js",
6059
"test:plugin": "mocha test/plugin/plugin_test.js",
6160
"def": "./runok.js def",
6261
"dev:graphql": "node test/data/graphql/index.js",
@@ -101,7 +100,6 @@
101100
"monocart-coverage-reports": "2.10.3",
102101
"ms": "2.1.3",
103102
"ora-classic": "5.4.2",
104-
"pactum": "3.7.1",
105103
"parse-function": "5.6.10",
106104
"parse5": "7.1.2",
107105
"promise-retry": "1.1.1",

test/helper/MockServer_test.js

-135
Original file line numberDiff line numberDiff line change
@@ -1,135 +0,0 @@
1-
const path = require('path')
2-
3-
const chai = require('chai')
4-
5-
const expect = chai.expect
6-
7-
const { like } = require('pactum-matchers')
8-
const MockServer = require('../../lib/helper/MockServer')
9-
const REST = require('../../lib/helper/REST')
10-
11-
global.codeceptjs = require('../../lib')
12-
13-
let I
14-
let restClient
15-
const port = 65000
16-
const api_url = `http://0.0.0.0:${port}`
17-
18-
describe('MockServer Helper', function () {
19-
this.timeout(3000)
20-
this.retries(1)
21-
22-
before(() => {
23-
global.codecept_dir = path.join(__dirname, '/../data')
24-
25-
I = new MockServer({ port })
26-
restClient = new REST({
27-
endpoint: api_url,
28-
defaultHeaders: {
29-
'X-Test': 'test',
30-
},
31-
})
32-
})
33-
34-
beforeEach(async () => {
35-
await I.startMockServer()
36-
})
37-
38-
afterEach(async () => {
39-
await I.stopMockServer()
40-
})
41-
42-
describe('#startMockServer', () => {
43-
it('should start the mock server with custom port', async () => {
44-
global.debugMode = true
45-
await I.startMockServer(6789)
46-
await I.stopMockServer()
47-
global.debugMode = undefined
48-
})
49-
})
50-
51-
describe('#addInteractionToMockServer', () => {
52-
it('should return the correct response', async () => {
53-
await I.addInteractionToMockServer({
54-
request: {
55-
method: 'GET',
56-
path: '/api/hello',
57-
},
58-
response: {
59-
status: 200,
60-
body: {
61-
say: 'hello to mock server',
62-
},
63-
},
64-
})
65-
const res = await restClient.sendGetRequest('/api/hello')
66-
expect(res.data).to.eql({ say: 'hello to mock server' })
67-
})
68-
69-
it('should return 404 when not found route', async () => {
70-
const res = await restClient.sendGetRequest('/api/notfound')
71-
expect(res.status).to.eql(404)
72-
})
73-
74-
it('should return the strong Match on Query Params', async () => {
75-
await I.addInteractionToMockServer({
76-
request: {
77-
method: 'GET',
78-
path: '/api/users',
79-
queryParams: {
80-
id: 1,
81-
},
82-
},
83-
response: {
84-
status: 200,
85-
body: {
86-
user: 1,
87-
},
88-
},
89-
})
90-
91-
await I.addInteractionToMockServer({
92-
request: {
93-
method: 'GET',
94-
path: '/api/users',
95-
queryParams: {
96-
id: 2,
97-
},
98-
},
99-
response: {
100-
status: 200,
101-
body: {
102-
user: 2,
103-
},
104-
},
105-
})
106-
let res = await restClient.sendGetRequest('/api/users?id=1')
107-
expect(res.data).to.eql({ user: 1 })
108-
res = await restClient.sendGetRequest('/api/users?id=2')
109-
expect(res.data).to.eql({ user: 2 })
110-
})
111-
112-
it('should check the stateful behavior', async () => {
113-
await I.addInteractionToMockServer({
114-
request: {
115-
method: 'GET',
116-
path: '/api/projects/{id}',
117-
pathParams: {
118-
id: like('random-id'),
119-
},
120-
},
121-
stores: {
122-
ProjectId: 'req.pathParams.id',
123-
},
124-
response: {
125-
status: 200,
126-
body: {
127-
id: '$S{ProjectId}',
128-
},
129-
},
130-
})
131-
const res = await restClient.sendGetRequest('/api/projects/10')
132-
expect(res.data).to.eql({ id: '10' })
133-
})
134-
})
135-
})

0 commit comments

Comments
 (0)