Skip to content

Commit

Permalink
Remove DELETE /users/:id/subscriptions/:id endpoint (#530)
Browse files Browse the repository at this point in the history
* Remove DELETE /users/:username/subscriptions/:subscriptionId endpoint

Signed-off-by: Hung-Han (Henry) Chen <[email protected]>

* Remove tests

Signed-off-by: Hung-Han (Henry) Chen <[email protected]>

* Fix lint

Signed-off-by: Hung-Han (Henry) Chen <[email protected]>

---------

Signed-off-by: Hung-Han (Henry) Chen <[email protected]>
  • Loading branch information
chenhunghan authored Jan 11, 2024
1 parent 204cf47 commit 3cf3c1d
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 158 deletions.
129 changes: 0 additions & 129 deletions integration-test/UserService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import {
NotFoundException,
UnauthorizedException,
UsernameAlreadyExistsException,
ConflictException,
} from "../src/exceptions";
import { License } from "../src/types/types";
import { testAvatar } from "./avatar";

jest.setTimeout(10000);
Expand Down Expand Up @@ -151,133 +149,6 @@ describe("UserService", () => {
});

describe("License", () => {
describe("activateSubscription", () => {
beforeEach(async () => {
try {
// Make sure the subscription isn't yet active
const license = {
subscriptionId: userSteve.subscriptionId!,
};

await stevePlatform.client.user.deactivateSubscription({
username: userSteve.username,
license,
});
} catch (_: unknown) {}
});

it.skip("rejects requests with invalid username", async () => {
const license: License = {
subscriptionId: userSteve.subscriptionId!,
type: "pro",
};

return expect(
stevePlatform.client.user.activateSubscription({ username: "FAKE_USER", license }),
).rejects.toThrowError(ForbiddenException);
});

it.skip("rejects requests with invalid subscriptionId", async () => {
const license: License = {
subscriptionId: "FAKE_SUBSCRIPTION",
type: "pro",
};

return expect(
stevePlatform.client.user.activateSubscription({ username: userSteve.username, license }),
).rejects.toThrowError(NotFoundException);
});

it.skip("rejects requests for already existing subscriptions", async () => {
const license: License = {
subscriptionId: userSteve.subscriptionId!,
type: "pro",
};

await stevePlatform.client.user.activateSubscription({
username: userSteve.username,
license,
});

return expect(
stevePlatform.client.user.activateSubscription({ username: userSteve.username, license }),
).rejects.toThrowError(ConflictException);
});

it.skip("returns the activated license", async () => {
const license: License = {
subscriptionId: userSteve.subscriptionId!,
type: "pro",
};

const result = await stevePlatform.client.user.activateSubscription({
username: userSteve.username,
license,
});

expect(result).toEqual(license);
});
});

describe("deactivateSubscription", () => {
beforeEach(async () => {
// Make sure the subscription is active
try {
const license: License = {
subscriptionId: userAdam.subscriptionId!,
type: "pro",
};

await adamPlatform.client.user.activateSubscription({
username: userAdam.username,
license,
});
} catch (_: unknown) {}
});

afterEach(async () => {
// Make sure the subscription is deactivated
try {
const license: License = {
subscriptionId: userAdam.subscriptionId!,
type: "pro",
};

await adamPlatform.client.user.deactivateSubscription({
username: userAdam.username,
license,
});
} catch (_: unknown) {}
});

it.skip("rejects requests with invalid username", async () => {
adamPlatform.fakeToken = undefined;

return expect(
adamPlatform.client.user.deactivateSubscription({
username: "FAKE_USER",
license: { subscriptionId: userAdam.subscriptionId! },
}),
).rejects.toThrowError(ForbiddenException);
});

it.skip("rejects requests with invalid subscriptionId", async () =>
expect(
adamPlatform.client.user.deactivateSubscription({
username: userAdam.username,
license: { subscriptionId: "FAKE_SUBSCRIPTION" },
}),
).rejects.toThrowError(NotFoundException));

it.skip("returns undefined after subscription deactivation", async () =>
expect(
adamPlatform.client.user.deactivateSubscription({
username: userAdam.username,
license: { subscriptionId: userAdam.subscriptionId! },
}),
).resolves.toBeUndefined());
});

describe("Get user subscriptions", () => {
it("Should get list of subscriptions", async () => {
const subscriptions = [
Expand Down
29 changes: 0 additions & 29 deletions src/UserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,35 +559,6 @@ class UserService extends Base {
return json as unknown as OfflineActivationCode;
}

async deactivateSubscription({
username,
license,
}: {
username: string;
license: Pick<License, "subscriptionId">;
}): Promise<void> {
const { apiEndpointAddress, fetch } = this.lensPlatformClient;
const url = `${apiEndpointAddress}/users/${username}/subscriptions/${license.subscriptionId}`;

await throwExpected(async () => fetch.delete(url), {
404(error) {
const message = error?.body.message;

if (typeof message === "string") {
if (message.includes("User")) {
return new UserNameNotFoundException(username);
}
}

return new NotFoundException(`Recurly subscription ${license.subscriptionId} not found`);
},
403: () =>
new ForbiddenException(`Modification of user licenses for ${username} is forbidden`),
400: () => new BadRequestException(),
422: (error) => new UnprocessableEntityException(error?.body.message),
});
}

async deactivateSubscriptionSeat({
username,
license,
Expand Down

0 comments on commit 3cf3c1d

Please sign in to comment.