-
Notifications
You must be signed in to change notification settings - Fork 197
Expand file tree
/
Copy pathservice.test.js.twig
More file actions
38 lines (32 loc) · 2.36 KB
/
service.test.js.twig
File metadata and controls
38 lines (32 loc) · 2.36 KB
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
const Client = require("../../lib/client");
const InputFile = require("../../lib/inputFile");
const {{ service.name | caseUcfirst }} = require("../../lib/services/{{ service.name | caseCamel }}");
const mockedAxios = require("axios");
jest.mock('axios', () => jest.fn());
describe('{{ service.name | caseUcfirst }}', () => {
const client = new Client();
const {{ service.name | caseCamel }} = new {{ service.name | caseUcfirst }}(client);
{% for method in service.methods ~%}
test('test method {{ method.name | caseCamel }}()', async () => {
{%~ if method.type == 'webAuth' %}
const data = '';
{%~ elseif method.type == 'location' %}
const data = new Uint8Array(0);
{%~ else %}
{%- if method.responseModel and method.responseModel != 'any' %}
const data = {
{%- for definition in spec.definitions ~%}{%~ if definition.name == method.responseModel -%}{%~ for property in definition.properties | filter((param) => param.required) ~%}
'{{ property.name | escapeDollarSign }}': {% if property.type == 'object' %}{}{% elseif property.type == 'array' %}[]{% elseif property.type == 'string' %}'{{ property.example | escapeDollarSign }}'{% elseif property.type == 'boolean' %}true{% else %}{{ property.example }}{% endif %},{%~ endfor ~%}{% set break = true %}{%- else -%}{% set continue = true %}{%- endif -%}{%~ endfor -%}
};
{%~ else %}
const data = '';
{%~ endif %}
{%~ endif %}
mockedAxios.mockImplementation(() => Promise.resolve({data: data}));
const response = await {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({%~ for parameter in method.parameters.all | filter((param) => param.required) ~%}
{% if parameter.type == 'object' %}{}{% elseif parameter.type == 'array' %}[]{% elseif parameter.type == 'file' %}InputFile.fromBuffer(new Uint8Array(0), 'image.png'){% elseif parameter.type == 'boolean' %}true{% elseif parameter.type == 'string' %}'{% if parameter.example is not empty %}{{ parameter.example | escapeDollarSign }}{% endif %}'{% elseif parameter.type == 'integer' and parameter['x-example'] is empty %}1{% elseif parameter.type == 'number' and parameter['x-example'] is empty %}1.0{% else %}{{ parameter.example }}{%~ endif ~%},{%~ endfor ~%}
);
expect(response).toEqual(data);
});
{% endfor %}
})