Skip to content

Commit

Permalink
feat: publish from release/v12 (#551)
Browse files Browse the repository at this point in the history
* feat: publish from release/v12

* fix: integration tests

* Remove `DELETE /users/:id/subscriptions/:id` endpoint (#530)

* 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]>

* Remove unused `UserService.getUserSubscription` (#533)

* Remove unused UserService.getUserSubscription

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

* Remove tests

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

---------

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

* Drop the need to SSO certificate for SAML (#520)

* Drop the need to SSO certificate for SAML

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

* Fix tests and type

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

---------

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

---------

Signed-off-by: Hung-Han (Henry) Chen <[email protected]>
Co-authored-by: Henry Chen <[email protected]>
  • Loading branch information
panuhorsmalahti and chenhunghan authored Jun 28, 2024
1 parent 7fccecc commit 52fb28d
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 212 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Lint Repo
on:
push:
branches:
- main
- release/v12
pull_request:

jobs:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

#
# This CI triggered when a PR is merged in main branch.
# This CI triggered when a PR is merged in release/v12 branch.
#
# 1. Increase version number (e.g. 0.0.1 => 0.0.2) in package.json and add a git tag
# 2. Publish to npm registry
Expand Down Expand Up @@ -38,7 +38,7 @@ jobs:
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: main
branch: release/v12
tags: true

publish:
Expand Down
166 changes: 4 additions & 162 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 All @@ -296,6 +167,8 @@ describe("UserService", () => {
customFields: [],
companyName: "sdgfdgdfg",
accountCode: "f63ed988-017a-4a0f-8486-cc8cf5ec6f32",
autoRenew: true,
collectionMethod: "automatic",
isBusinessAccount: false,
state: "active",
pendingChange: {
Expand All @@ -318,6 +191,8 @@ describe("UserService", () => {
customFields: [],
companyName: "sdgfdgdfg",
accountCode: "f63ed988-017a-4a0f-8486-cc8cf5ec6f32",
autoRenew: true,
collectionMethod: "automatic",
isBusinessAccount: false,
state: "active",
pendingChange: {
Expand All @@ -333,39 +208,6 @@ describe("UserService", () => {
expect(userSubscriptions).toEqual(subscriptions);
});
});

describe("Get user subscription", () => {
it("Should get subscription", async () => {
const subscription = {
currentPeriodEndsAt: "2024-07-01T08:01:22.000Z",
currentPeriodStartedAt: "2023-07-01T08:01:22.000Z",
id: "6327929c2cfb8762b99eec44ddb3c3c4",
planCode: "pro-yearly",
planName: "Lens Desktop Pro",
seats: 1,
shortSubscriptionId: "r55uxv78pktg",
trialEndsAt: null,
trialStartedAt: null,
unitAmount: 199,
usedSeats: [],
customFields: [],
companyName: "sdgfdgdfg",
accountCode: "f63ed988-017a-4a0f-8486-cc8cf5ec6f32",
isBusinessAccount: false,
state: "active",
pendingChange: {
activateAt: null,
quantity: null,
},
};
const userSubscription = await bobPlatform.client.user.getUserSubscription(
userBob.username,
subscription.id,
);

expect(userSubscription).toEqual(subscription);
});
});
});

describe("getBillingPageToken", () => {
Expand Down
7 changes: 4 additions & 3 deletions integration-test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { config } from "./configuration";

export class TestPlatform {
public fakeToken?: string;

public readonly client: LensPlatformClient;

constructor(private readonly accessToken: string) {
Expand All @@ -26,14 +27,14 @@ export const testPlatformFactory = async (username: string, password: string) =>
secret: "<client-secret>",
},
auth: {
tokenHost: config.tokenHost,
tokenHost: config.keyCloakAddress,
tokenPath: "/auth/realms/lensCloud/protocol/openid-connect/token",
},
});

const tokenParams = {
username: username,
password: password,
username,
password,
scope: "openid",
};

Expand Down
4 changes: 0 additions & 4 deletions src/BusinessService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,10 +405,6 @@ export interface BusinessSsoSamlDto {
* this SAML Service Provider (from Keycloak docs)
*/
idpEntityId: string;
/**
* IDP certificate
*/
certificate: string;
/**
* SAML SSO type
*/
Expand Down
43 changes: 3 additions & 40 deletions src/UserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ export type SubscriptionInfo = {
*/
accountCode?: string | null;

autoRenew: boolean;
collectionMethod: "manual" | "automatic";

/**
* Subscription seat used for offline
*/
Expand Down Expand Up @@ -441,17 +444,6 @@ class UserService extends Base {
return json as unknown as SubscriptionSeat[];
}

async getUserSubscription(username: string, subscriptionId: string): Promise<SubscriptionInfo> {
const { apiEndpointAddress, fetch } = this.lensPlatformClient;
const url = `${apiEndpointAddress}/users/${username}/subscriptions/${subscriptionId}`;
const json = await throwExpected(async () => fetch.get(url), {
404: (error) => new NotFoundException(error?.body.message),
403: () => new ForbiddenException(`Access to user ${username} is forbidden`),
});

return json as unknown as SubscriptionInfo;
}

async activateSubscription({
username,
license,
Expand Down Expand Up @@ -552,35 +544,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 52fb28d

Please sign in to comment.