@@ -6,40 +6,57 @@ import { {{operations.classname}} } from "../../api";
6
6
import { {{import.classname}} } from '../{{import.filename}}';
7
7
{% endfor %}
8
8
9
- import * as nock from "nock";
9
+ import { http, HttpResponse } from "msw";
10
+ import { setupServer } from "msw/node";
10
11
import { deepEqual, equal } from "assert";
11
12
12
13
const pkg = require("../../../../package.json");
13
14
14
15
const channel_access_token = "test_channel_access_token";
15
16
16
17
describe("{{operations.classname}}", () => {
17
- before(() => nock.disableNetConnect());
18
- afterEach(() => nock.cleanAll());
19
- after(() => nock.enableNetConnect());
18
+ const server = setupServer();
19
+ before(() => { server.listen() });
20
+ after(() => { server.close() });
21
+ afterEach(() => { server.resetHandlers() })
20
22
21
23
const client = new {{operations.classname}}({
22
24
channelAccessToken: channel_access_token,
23
25
});
24
26
25
27
{% for op in operations.operation %}
26
28
it("{{op.nickname}}", async () => {
27
- const scope = nock("{{endpoint(operations.classname)}}", {
28
- reqheaders: {
29
- Authorization: `Bearer ${channel_access_token}`,
30
- "User-Agent": `${pkg.name}/${pkg.version}`,
31
- },
32
- })
33
- .{{ op.httpMethod|lower }}((u) => u.includes("{{op.path}}"
29
+ let requestCount = 0;
30
+
31
+ const endpoint = "{{endpoint(operations.classname)}}{{op.path}}"
34
32
{% for param in op.allParams -%}
35
33
{% if param.isNumber or param.isInteger or param.isLong -%}
36
34
.replace("{{ "{" + param.paramName + "}" }}", "0") // number
37
35
{% elseif param.isString -%}
38
36
.replace("{{ "{" + param.paramName + "}" }}", "DUMMY") // string
39
- {% endif %}
37
+ {% endif - %}
40
38
{% endfor %}{# allParams #}
41
- ))
42
- .reply(200, {});
39
+ ;
40
+
41
+ server.use(
42
+ http.{{ op.httpMethod|lower }}(
43
+ endpoint,
44
+ ({ request, params, cookies }) => {
45
+ requestCount++;
46
+
47
+ equal(
48
+ request.headers.get("Authorization"),
49
+ `Bearer ${channel_access_token}`,
50
+ );
51
+ equal(
52
+ request.headers.get("User-Agent"),
53
+ `${pkg.name}/${pkg.version}`,
54
+ );
55
+
56
+ return HttpResponse.json({});
57
+ },
58
+ )
59
+ );
43
60
44
61
const res = await client.{{op.nickname}}(
45
62
{% for param in op.allParams -%}
@@ -63,7 +80,8 @@ describe("{{operations.classname}}", () => {
63
80
{% endif -%}
64
81
{% endfor %}
65
82
);
66
- equal(scope.isDone(), true);
83
+
84
+ equal(requestCount, 1);
67
85
});
68
86
69
87
{% endfor %}{# op #}
0 commit comments