Skip to content

Commit de4d115

Browse files
committed
- Working Angular tests
1 parent 53241c1 commit de4d115

File tree

11 files changed

+177
-96
lines changed

11 files changed

+177
-96
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Before working on a Pull Request, create an issue explaining what you want to co
88
This ensures that your pull request won't go unnoticed, and that you are not contributing
99
something that is not suitable for the project.
1010

11-
If you are unfamiliar with Github Pull Requests, please read the following documentation:
11+
If you are unfamiliar with GitHub Pull Requests, please read the following documentation:
1212
https://help.github.com/articles/using-pull-requests
1313

1414
**Your Pull Request must:**

jest.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const config: Config.InitialOptions = {
3333
'<rootDir>/test/e2e/client.axios.spec.ts',
3434
'<rootDir>/test/e2e/client.babel.spec.ts',
3535
],
36+
testPathIgnorePatterns: ['<rootDir>/test/e2e/generated'],
3637
},
3738
],
3839
collectCoverageFrom: ['<rootDir>/src/**/*.ts', '!<rootDir>/src/**/*.d.ts', '!<rootDir>/bin', '!<rootDir>/dist'],

src/templates/core/angular/getHeaders.hbs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Pr
44
const password = await resolve(options, config.PASSWORD);
55
const additionalHeaders = await resolve(options, config.HEADERS);
66

7-
const defaultHeaders = Object.entries({
7+
const headers = Object.entries({
88
Accept: 'application/json',
99
...additionalHeaders,
1010
...options.headers,
@@ -15,28 +15,26 @@ const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Pr
1515
[key]: String(value),
1616
}), {} as Record<string, string>);
1717

18-
const headers = new HttpHeaders(defaultHeaders);
19-
2018
if (isStringWithValue(token)) {
21-
headers.append('Authorization', `Bearer ${token}`);
19+
headers['Authorization'] = `Bearer ${token}`;
2220
}
2321

2422
if (isStringWithValue(username) && isStringWithValue(password)) {
2523
const credentials = base64(`${username}:${password}`);
26-
headers.append('Authorization', `Basic ${credentials}`);
24+
headers['Authorization'] = `Basic ${credentials}`;
2725
}
2826

2927
if (options.body) {
3028
if (options.mediaType) {
31-
headers.append('Content-Type', options.mediaType);
29+
headers['Content-Type'] = options.mediaType;
3230
} else if (isBlob(options.body)) {
33-
headers.append('Content-Type', options.body.type || 'application/octet-stream');
31+
headers['Content-Type'] = options.body.type || 'application/octet-stream';
3432
} else if (isString(options.body)) {
35-
headers.append('Content-Type', 'text/plain');
33+
headers['Content-Type'] = 'text/plain';
3634
} else if (!isFormData(options.body)) {
37-
headers.append('Content-Type', 'application/json');
35+
headers['Content-Type'] = 'application/json';
3836
}
3937
}
4038

41-
return headers;
39+
return new HttpHeaders(headers);
4240
};

src/templates/core/fetch/getHeaders.hbs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Pr
44
const password = await resolve(options, config.PASSWORD);
55
const additionalHeaders = await resolve(options, config.HEADERS);
66

7-
const defaultHeaders = Object.entries({
7+
const headers = Object.entries({
88
Accept: 'application/json',
99
...additionalHeaders,
1010
...options.headers,
@@ -15,28 +15,28 @@ const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Pr
1515
[key]: String(value),
1616
}), {} as Record<string, string>);
1717

18-
const headers = new Headers(defaultHeaders);
18+
const headers =
1919

2020
if (isStringWithValue(token)) {
21-
headers.append('Authorization', `Bearer ${token}`);
21+
headers['Authorization'] = `Bearer ${token}`;
2222
}
2323

2424
if (isStringWithValue(username) && isStringWithValue(password)) {
2525
const credentials = base64(`${username}:${password}`);
26-
headers.append('Authorization', `Basic ${credentials}`);
26+
headers['Authorization'] = `Basic ${credentials}`;
2727
}
2828

2929
if (options.body) {
3030
if (options.mediaType) {
31-
headers.append('Content-Type', options.mediaType);
31+
headers['Content-Type'] = options.mediaType;
3232
} else if (isBlob(options.body)) {
33-
headers.append('Content-Type', options.body.type || 'application/octet-stream');
33+
headers['Content-Type'] = options.body.type || 'application/octet-stream';
3434
} else if (isString(options.body)) {
35-
headers.append('Content-Type', 'text/plain');
35+
headers['Content-Type'] = 'text/plain';
3636
} else if (!isFormData(options.body)) {
37-
headers.append('Content-Type', 'application/json');
37+
headers['Content-Type'] = 'application/json';
3838
}
3939
}
4040

41-
return headers;
41+
return new Headers(headers);
4242
};

src/templates/core/node/getHeaders.hbs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,26 @@ const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Pr
1515
[key]: String(value),
1616
}), {} as Record<string, string>);
1717

18-
const headers = new Headers(defaultHeaders);
19-
2018
if (isStringWithValue(token)) {
21-
headers.append('Authorization', `Bearer ${token}`);
19+
headers['Authorization'] = `Bearer ${token}`;
2220
}
2321

2422
if (isStringWithValue(username) && isStringWithValue(password)) {
2523
const credentials = base64(`${username}:${password}`);
26-
headers.append('Authorization', `Basic ${credentials}`);
24+
headers['Authorization'] = `Basic ${credentials}`;
2725
}
2826

2927
if (options.body) {
3028
if (options.mediaType) {
31-
headers.append('Content-Type', options.mediaType);
29+
headers['Content-Type'] = options.mediaType;
3230
} else if (isBlob(options.body)) {
33-
headers.append('Content-Type', 'application/octet-stream');
31+
headers['Content-Type'] = 'application/octet-stream';
3432
} else if (isString(options.body)) {
35-
headers.append('Content-Type', 'text/plain');
33+
headers['Content-Type'] = 'text/plain';
3634
} else if (!isFormData(options.body)) {
37-
headers.append('Content-Type', 'application/json');
35+
headers['Content-Type'] = 'application/json';
3836
}
3937
}
40-
return headers;
38+
39+
return new Headers(headers);
4140
};

src/templates/core/xhr/getHeaders.hbs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,26 @@ const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Pr
1515
[key]: String(value),
1616
}), {} as Record<string, string>);
1717

18-
const headers = new Headers(defaultHeaders);
19-
2018
if (isStringWithValue(token)) {
21-
headers.append('Authorization', `Bearer ${token}`);
19+
headers['Authorization'] = `Bearer ${token}`;
2220
}
2321

2422
if (isStringWithValue(username) && isStringWithValue(password)) {
2523
const credentials = base64(`${username}:${password}`);
26-
headers.append('Authorization', `Basic ${credentials}`);
24+
headers['Authorization'] = `Basic ${credentials}`;
2725
}
2826

2927
if (options.body) {
3028
if (options.mediaType) {
31-
headers.append('Content-Type', options.mediaType);
29+
headers['Content-Type'] = options.mediaType;
3230
} else if (isBlob(options.body)) {
33-
headers.append('Content-Type', options.body.type || 'application/octet-stream');
31+
headers['Content-Type'] = options.body.type || 'application/octet-stream';
3432
} else if (isString(options.body)) {
35-
headers.append('Content-Type', 'text/plain');
33+
headers['Content-Type'] = 'text/plain';
3634
} else if (!isFormData(options.body)) {
37-
headers.append('Content-Type', 'application/json');
35+
headers['Content-Type'] = 'application/json';
3836
}
3937
}
40-
return headers;
38+
39+
return new Headers(headers);
4140
};

test/__snapshots__/index.spec.ts.snap

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Pr
365365
const password = await resolve(options, config.PASSWORD);
366366
const additionalHeaders = await resolve(options, config.HEADERS);
367367

368-
const defaultHeaders = Object.entries({
368+
const headers = Object.entries({
369369
Accept: 'application/json',
370370
...additionalHeaders,
371371
...options.headers,
@@ -376,30 +376,30 @@ const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Pr
376376
[key]: String(value),
377377
}), {} as Record<string, string>);
378378

379-
const headers = new Headers(defaultHeaders);
379+
const headers =
380380

381381
if (isStringWithValue(token)) {
382-
headers.append('Authorization', \`Bearer \${token}\`);
382+
headers['Authorization'] = \`Bearer \${token}\`;
383383
}
384384

385385
if (isStringWithValue(username) && isStringWithValue(password)) {
386386
const credentials = base64(\`\${username}:\${password}\`);
387-
headers.append('Authorization', \`Basic \${credentials}\`);
387+
headers['Authorization'] = \`Basic \${credentials}\`;
388388
}
389389

390390
if (options.body) {
391391
if (options.mediaType) {
392-
headers.append('Content-Type', options.mediaType);
392+
headers['Content-Type'] = options.mediaType;
393393
} else if (isBlob(options.body)) {
394-
headers.append('Content-Type', options.body.type || 'application/octet-stream');
394+
headers['Content-Type'] = options.body.type || 'application/octet-stream';
395395
} else if (isString(options.body)) {
396-
headers.append('Content-Type', 'text/plain');
396+
headers['Content-Type'] = 'text/plain';
397397
} else if (!isFormData(options.body)) {
398-
headers.append('Content-Type', 'application/json');
398+
headers['Content-Type'] = 'application/json';
399399
}
400400
}
401401

402-
return headers;
402+
return new Headers(headers);
403403
};
404404

405405
const getRequestBody = (options: ApiRequestOptions): any => {
@@ -3268,7 +3268,7 @@ const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Pr
32683268
const password = await resolve(options, config.PASSWORD);
32693269
const additionalHeaders = await resolve(options, config.HEADERS);
32703270

3271-
const defaultHeaders = Object.entries({
3271+
const headers = Object.entries({
32723272
Accept: 'application/json',
32733273
...additionalHeaders,
32743274
...options.headers,
@@ -3279,30 +3279,30 @@ const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Pr
32793279
[key]: String(value),
32803280
}), {} as Record<string, string>);
32813281

3282-
const headers = new Headers(defaultHeaders);
3282+
const headers =
32833283

32843284
if (isStringWithValue(token)) {
3285-
headers.append('Authorization', \`Bearer \${token}\`);
3285+
headers['Authorization'] = \`Bearer \${token}\`;
32863286
}
32873287

32883288
if (isStringWithValue(username) && isStringWithValue(password)) {
32893289
const credentials = base64(\`\${username}:\${password}\`);
3290-
headers.append('Authorization', \`Basic \${credentials}\`);
3290+
headers['Authorization'] = \`Basic \${credentials}\`;
32913291
}
32923292

32933293
if (options.body) {
32943294
if (options.mediaType) {
3295-
headers.append('Content-Type', options.mediaType);
3295+
headers['Content-Type'] = options.mediaType;
32963296
} else if (isBlob(options.body)) {
3297-
headers.append('Content-Type', options.body.type || 'application/octet-stream');
3297+
headers['Content-Type'] = options.body.type || 'application/octet-stream';
32983298
} else if (isString(options.body)) {
3299-
headers.append('Content-Type', 'text/plain');
3299+
headers['Content-Type'] = 'text/plain';
33003300
} else if (!isFormData(options.body)) {
3301-
headers.append('Content-Type', 'application/json');
3301+
headers['Content-Type'] = 'application/json';
33023302
}
33033303
}
33043304

3305-
return headers;
3305+
return new Headers(headers);
33063306
};
33073307

33083308
const getRequestBody = (options: ApiRequestOptions): any => {

test/e2e/assets/index.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<!DOCTYPE html>
2-
<html lang="en">
3-
<head>
4-
<meta charset="utf-8">
5-
<title></title>
6-
<script type="module" src="js/main.js"></script>
7-
</head>
8-
<body>
9-
</body>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title></title>
6+
<script type="module" src="js/main.js"></script>
7+
</head>
8+
<body>
9+
</body>
1010
</html>

test/e2e/assets/main-angular.ts

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Component, NgModule } from '@angular/core';
33
import { BrowserModule } from '@angular/platform-browser';
44
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
55

6+
import { OpenAPI } from './core/OpenAPI';
67
import { CollectionFormatService } from './services/CollectionFormatService';
78
import { ComplexService } from './services/ComplexService';
89
import { DefaultService } from './services/DefaultService';
@@ -21,42 +22,43 @@ import { TypesService } from './services/TypesService';
2122

2223
@Component({
2324
selector: 'app-root',
24-
template: `<div>Angular</div>`,
25+
template: `<div>Angular is ready</div>`,
2526
})
2627
export class AppComponent {
2728
constructor(
2829
private readonly collectionFormatService: CollectionFormatService,
29-
private readonly complexServiceService: ComplexService,
30-
private readonly defaultServiceService: DefaultService,
31-
private readonly defaultsServiceService: DefaultsService,
32-
private readonly duplicateServiceService: DuplicateService,
33-
private readonly errorServiceService: ErrorService,
34-
private readonly headerServiceService: HeaderService,
35-
private readonly multipleTags1ServiceService: MultipleTags1Service,
36-
private readonly multipleTags2ServiceService: MultipleTags2Service,
37-
private readonly multipleTags3ServiceService: MultipleTags3Service,
38-
private readonly noContentServiceService: NoContentService,
39-
private readonly parametersServiceService: ParametersService,
40-
private readonly responseServiceService: ResponseService,
41-
private readonly simpleServiceService: SimpleService,
42-
private readonly typesServiceService: TypesService
30+
private readonly complexService: ComplexService,
31+
private readonly defaultService: DefaultService,
32+
private readonly defaultsService: DefaultsService,
33+
private readonly duplicateService: DuplicateService,
34+
private readonly errorService: ErrorService,
35+
private readonly headerService: HeaderService,
36+
private readonly multipleTags1Service: MultipleTags1Service,
37+
private readonly multipleTags2Service: MultipleTags2Service,
38+
private readonly multipleTags3Service: MultipleTags3Service,
39+
private readonly noContentService: NoContentService,
40+
private readonly parametersService: ParametersService,
41+
private readonly responseService: ResponseService,
42+
private readonly simpleService: SimpleService,
43+
private readonly typesService: TypesService
4344
) {
4445
(window as any).api = {
45-
collectionFormatService,
46-
complexServiceService,
47-
defaultServiceService,
48-
defaultsServiceService,
49-
duplicateServiceService,
50-
errorServiceService,
51-
headerServiceService,
52-
multipleTags1ServiceService,
53-
multipleTags2ServiceService,
54-
multipleTags3ServiceService,
55-
noContentServiceService,
56-
parametersServiceService,
57-
responseServiceService,
58-
simpleServiceService,
59-
typesServiceService,
46+
OpenAPI,
47+
CollectionFormatService: collectionFormatService,
48+
ComplexService: complexService,
49+
DefaultService: defaultService,
50+
DefaultsService: defaultsService,
51+
DuplicateService: duplicateService,
52+
ErrorService: errorService,
53+
HeaderService: headerService,
54+
MultipleTags1Service: multipleTags1Service,
55+
MultipleTags2Service: multipleTags2Service,
56+
MultipleTags3Service: multipleTags3Service,
57+
NoContentService: noContentService,
58+
ParametersService: parametersService,
59+
ResponseService: responseService,
60+
SimpleService: simpleService,
61+
TypesService: typesService,
6062
};
6163
}
6264
}

0 commit comments

Comments
 (0)