Skip to content

Commit 26473d8

Browse files
committed
tests(angular): pet api service expectations
Signed-off-by: Vojtech Mašek <[email protected]>
1 parent b8e2df2 commit 26473d8

File tree

2 files changed

+74
-3
lines changed

2 files changed

+74
-3
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
2+
import { inject, TestBed } from '@angular/core/testing';
3+
import { PetAPIClient, PetAPIClientModule } from '../api-all-tags/pet';
4+
import { DUMMY_DOMAIN } from './tests-constants';
5+
6+
describe('PetService', () => {
7+
beforeEach(() => {
8+
TestBed.configureTestingModule({
9+
imports: [
10+
HttpClientTestingModule,
11+
PetAPIClientModule.forRoot({
12+
domain: DUMMY_DOMAIN,
13+
})
14+
],
15+
});
16+
});
17+
18+
it('should be initialized', inject([PetAPIClient], async (api: PetAPIClient) => {
19+
await expect(api).toBeTruthy();
20+
await expect(api.domain).toBe(DUMMY_DOMAIN);
21+
}));
22+
23+
it('should set id to path', inject(
24+
[PetAPIClient, HttpTestingController],
25+
async (api, backend) => {
26+
api.getPetById({petId: 42}).subscribe(async (data) => {
27+
await expect(data).toBeNull();
28+
});
29+
30+
backend
31+
.expectOne({
32+
method: 'GET',
33+
url: '/pet/42'
34+
})
35+
.flush(null);
36+
}
37+
));
38+
39+
it('should set name and status to query', inject(
40+
[PetAPIClient, HttpTestingController],
41+
async (api, backend) => {
42+
api.updatePetWithQuery({
43+
petId: 42,
44+
name: 'wololo',
45+
status: 'OK'
46+
}).subscribe(() => {});
47+
48+
const req = backend
49+
.expectOne(req => req.method === 'POST' && req.url === '/pet/42');
50+
51+
await expect(req.request.params.getAll('name')).toEqual(['wololo']);
52+
await expect(req.request.params.getAll('status')).toEqual(['OK']);
53+
}
54+
));
55+
56+
it('should delete pet with ID and set api key header', inject(
57+
[PetAPIClient, HttpTestingController],
58+
async (api, backend) => {
59+
api.deletePet({
60+
apiKey: 'DUMMY_API_KEY',
61+
petId: 42,
62+
}).subscribe(() => {});
63+
64+
const req = backend
65+
.expectOne({
66+
method: 'DELETE',
67+
url: '/pet/42',
68+
});
69+
70+
await expect(req.request.headers.get('api_key')).toEqual('DUMMY_API_KEY')
71+
}
72+
));
73+
});

tests/test-angular-project/swagger.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,7 @@ paths:
159159
tags:
160160
- "pet"
161161
summary: "Updates a pet in the store with form data"
162-
operationId: "updatePetWithForm"
163-
consumes:
164-
- "application/x-www-form-urlencoded"
162+
operationId: "updatePetWithQuery"
165163
produces:
166164
- "application/json"
167165
parameters:

0 commit comments

Comments
 (0)