Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
Merge pull request #30 from aerogear/VARIANT_DELETE_FIX
Browse files Browse the repository at this point in the history
Fixed variant delete
  • Loading branch information
ziccardi committed Apr 8, 2020
2 parents 2b08370 + 6527e94 commit b297e03
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# UnifiedPush Server Admin Client

![Build](https://github.com/aerogear/unifiedpush-admin-client/workflows/build/badge.svg)
[![Coverage Status](https://coveralls.io/repos/github/aerogear/unifiedpush-admin-client/badge.svg)](https://coveralls.io/github/aerogear/unifiedpush-admin-client)
[![Coverage Status](https://coveralls.io/repos/github/aerogear/unifiedpush-admin-client/badge.svg?branch=master)](https://coveralls.io/github/aerogear/unifiedpush-admin-client)

The _UnifiedPush Server Admin_ library allows to admin the UPS by javascript or typescript code.

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aerogear/unifiedpush-admin-client",
"version": "0.1.3",
"version": "0.1.4",
"description": "Client library used to admin UPS with code",
"author": "AeroGear Team<aerogear@googlegroups.com>",
"homepage": "http://aerogear.org",
Expand Down
4 changes: 3 additions & 1 deletion src/variants/VariantsAdmin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ export class VariantsAdmin {

async delete(api: AxiosInstance, appId: string, filter?: VariantFilter) {
return Promise.all(
(await this.find(api, appId, filter)).map(variant => api.delete(`/applications/${appId}/${variant.variantID!}`))
(await this.find(api, appId, filter)).map(variant =>
api.delete(`/applications/${appId}/${variant.type}/${variant.variantID!}`).then(() => variant)
)
);
}
}
17 changes: 17 additions & 0 deletions test/UnifiedPushAdminClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ afterAll(() => {
});

const TEST_APP_ID = '2:2';
const TEST_VARIANT_ID = 'v-2:1';

describe('UnifiedPushAdminClient', () => {
const credentials: KeycloakCredentials = {
Expand Down Expand Up @@ -54,4 +55,20 @@ describe('UnifiedPushAdminClient', () => {
);
expect(variant).toEqual(TEST_NEW_VARIANT_CREATED);
});

it('Should delete a varianta', async () => {
const variantsBefore = await new UnifiedPushAdminClient(BASE_URL, credentials).variants.find(TEST_APP_ID, {
variantID: TEST_VARIANT_ID,
});
expect(variantsBefore).toBeDefined();
expect(variantsBefore).toHaveLength(1);
await new UnifiedPushAdminClient(BASE_URL, credentials).variants.delete(TEST_APP_ID, {
variantID: TEST_VARIANT_ID,
});
const variantsAfter = await new UnifiedPushAdminClient(BASE_URL, credentials).variants.find(TEST_APP_ID, {
variantID: TEST_VARIANT_ID,
});
expect(variantsAfter).toBeDefined();
expect(variantsAfter).toHaveLength(0);
});
});
6 changes: 3 additions & 3 deletions test/mocks/nockMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ export const mockUps = (baseUrl = BASE_URL, auth = false) =>
expect(requestBody.indexOf('name="certificate"')).not.toEqual(-1);
return TEST_NEW_VARIANT_CREATED;
})
.delete(/rest\/applications\/?[^\/]*\/?[^\/]*/)
.delete(/rest\/applications\/?[^\/]*\/?[^\/]*\/?[^\/]*/)
// tslint:disable-next-line:only-arrow-functions
.reply(200, function(uri, requestBody) {
const del = /rest\/applications\/?([^\/]*)\/?([^\/]*)/;
const del = /rest\/applications\/?([^\/]*)\/?([^\/]*)\/?([^\/]*)/;
const params = del.exec(uri)!;
const appid = params[1];
const varId = params[2];
const varId = params[3];
const app = mockData.find(appDel => appDel.pushApplicationID === appid)!;
const variants = app?.variants?.filter(variant => variant.variantID !== varId);

Expand Down

0 comments on commit b297e03

Please sign in to comment.