Skip to content

Commit ece4208

Browse files
authored
feat: delete versions (#109)
1 parent 263f7a4 commit ece4208

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

src/versions/versions-api-client/versions-api-client.e2e.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ describe('VersionsApiClient', () => {
4444
});
4545
});
4646

47+
describe('deleteVersions', () => {
48+
it('should return 200 for delete with valid database, application and version', async () => {
49+
const response = await client.deleteVersions(
50+
database,
51+
[{ application, version }]
52+
);
53+
54+
expect(response.status).toEqual(200);
55+
});
56+
});
57+
4758
describe('putFullDumps', () => {
4859
it('should return 403 because account is not licensed', async () => {
4960
const result = await client.putFullDumps(

src/versions/versions-api-client/versions-api-client.spec.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,38 @@ describe('VersionsApiClient', () => {
7777
});
7878
});
7979

80+
describe('deleteVersions', () => {
81+
it('should call delete with route containing database and appVersions', async () => {
82+
const appVersions = [
83+
{ application: 'myConsoleCrasher', version: '2022.4.20.0' },
84+
{ application: 'myConsoleCrasher', version: '2022.4.20.1' }
85+
];
86+
await versionsApiClient.deleteVersions(database, appVersions);
87+
88+
expect(fakeBugSplatApiClient.fetch).toHaveBeenCalledWith(
89+
`/api/versions?database=${database}&appVersions=${appVersions[0].application},${appVersions[0].version},${appVersions[1].application},${appVersions[1].version}`,
90+
jasmine.anything()
91+
);
92+
});
93+
94+
describe('error', () => {
95+
it('should throw if response is not 200', async () => {
96+
const fakeErrorResponse = createFakeResponseBody(400);
97+
fakeBugSplatApiClient.fetch.and.resolveTo(fakeErrorResponse);
98+
99+
await expectAsync(versionsApiClient.deleteVersions(database, [])).toBeRejectedWithError(`Error deleting symbols for ${database}- status 400`);
100+
});
101+
102+
it('should throw if response json Status is \'Failed\'', async () => {
103+
const message = '🤮';
104+
const fakeErrorResponse = createFakeResponseBody(200, { Status: 'Failed', Error: message });
105+
fakeBugSplatApiClient.fetch.and.resolveTo(fakeErrorResponse);
106+
107+
await expectAsync(versionsApiClient.deleteVersions(database, [])).toBeRejectedWithError(message);
108+
});
109+
});
110+
});
111+
80112
describe('putFullDumps', () => {
81113
const fullDumps = true;
82114
let result;

src/versions/versions-api-client/versions-api-client.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,29 @@ export class VersionsApiClient {
2828
};
2929
}
3030

31+
async deleteVersions(database: string, appVersions: Array<{ application: string, version: string }>): Promise<BugSplatResponse> {
32+
const appVersionsParam = appVersions.reduce((prev, curr) => [...prev, curr.application, curr.version], [] as Array<string>).join(',');
33+
const route = `${this.route}?database=${database}&appVersions=${appVersionsParam}`;
34+
const request = {
35+
method: 'DELETE',
36+
cache: 'no-cache',
37+
credentials: 'include',
38+
redirect: 'follow'
39+
} as RequestInit;
40+
41+
const response = await this._client.fetch(route, request);
42+
if (response.status !== 200) {
43+
throw new Error(`Error deleting symbols for ${database}-${appVersionsParam} status ${response.status}`);
44+
}
45+
46+
const json = await response.json() as Response;
47+
if (json.Status === 'Failed') {
48+
throw new Error(json.Error);
49+
}
50+
51+
return response;
52+
}
53+
3154
async putFullDumps(
3255
database: string,
3356
application: string,

0 commit comments

Comments
 (0)