From 52fb28ddc48b274ee3663fc0e275f13bea6a42a4 Mon Sep 17 00:00:00 2001 From: Panu Horsmalahti Date: Fri, 28 Jun 2024 11:12:57 +0300 Subject: [PATCH] feat: publish from release/v12 (#551) * 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 * Remove tests Signed-off-by: Hung-Han (Henry) Chen * Fix lint Signed-off-by: Hung-Han (Henry) Chen --------- Signed-off-by: Hung-Han (Henry) Chen * Remove unused `UserService.getUserSubscription` (#533) * Remove unused UserService.getUserSubscription Signed-off-by: Hung-Han (Henry) Chen * Remove tests Signed-off-by: Hung-Han (Henry) Chen --------- Signed-off-by: Hung-Han (Henry) Chen * Drop the need to SSO certificate for SAML (#520) * Drop the need to SSO certificate for SAML Signed-off-by: Hung-Han (Henry) Chen * Fix tests and type Signed-off-by: Hung-Han (Henry) Chen --------- Signed-off-by: Hung-Han (Henry) Chen --------- Signed-off-by: Hung-Han (Henry) Chen Co-authored-by: Henry Chen <1474479+chenhunghan@users.noreply.github.com> --- .github/workflows/lint.yaml | 2 +- .github/workflows/publish.yml | 4 +- integration-test/UserService.test.ts | 166 +-------------------------- integration-test/utils.ts | 7 +- src/BusinessService.ts | 4 - src/UserService.ts | 43 +------ 6 files changed, 14 insertions(+), 212 deletions(-) diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index f82dd31e..6e73c05e 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -2,7 +2,7 @@ name: Lint Repo on: push: branches: - - main + - release/v12 pull_request: jobs: diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 97428ae8..f5d4820b 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -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 @@ -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: diff --git a/integration-test/UserService.test.ts b/integration-test/UserService.test.ts index f379320a..433cd26e 100644 --- a/integration-test/UserService.test.ts +++ b/integration-test/UserService.test.ts @@ -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); @@ -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 = [ @@ -296,6 +167,8 @@ describe("UserService", () => { customFields: [], companyName: "sdgfdgdfg", accountCode: "f63ed988-017a-4a0f-8486-cc8cf5ec6f32", + autoRenew: true, + collectionMethod: "automatic", isBusinessAccount: false, state: "active", pendingChange: { @@ -318,6 +191,8 @@ describe("UserService", () => { customFields: [], companyName: "sdgfdgdfg", accountCode: "f63ed988-017a-4a0f-8486-cc8cf5ec6f32", + autoRenew: true, + collectionMethod: "automatic", isBusinessAccount: false, state: "active", pendingChange: { @@ -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", () => { diff --git a/integration-test/utils.ts b/integration-test/utils.ts index 3a994edc..2d3c72cf 100644 --- a/integration-test/utils.ts +++ b/integration-test/utils.ts @@ -5,6 +5,7 @@ import { config } from "./configuration"; export class TestPlatform { public fakeToken?: string; + public readonly client: LensPlatformClient; constructor(private readonly accessToken: string) { @@ -26,14 +27,14 @@ export const testPlatformFactory = async (username: string, password: string) => 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", }; diff --git a/src/BusinessService.ts b/src/BusinessService.ts index afd60af5..75c7ac6f 100644 --- a/src/BusinessService.ts +++ b/src/BusinessService.ts @@ -405,10 +405,6 @@ export interface BusinessSsoSamlDto { * this SAML Service Provider (from Keycloak docs) */ idpEntityId: string; - /** - * IDP certificate - */ - certificate: string; /** * SAML SSO type */ diff --git a/src/UserService.ts b/src/UserService.ts index a05b979c..aff698bb 100644 --- a/src/UserService.ts +++ b/src/UserService.ts @@ -110,6 +110,9 @@ export type SubscriptionInfo = { */ accountCode?: string | null; + autoRenew: boolean; + collectionMethod: "manual" | "automatic"; + /** * Subscription seat used for offline */ @@ -441,17 +444,6 @@ class UserService extends Base { return json as unknown as SubscriptionSeat[]; } - async getUserSubscription(username: string, subscriptionId: string): Promise { - 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, @@ -552,35 +544,6 @@ class UserService extends Base { return json as unknown as OfflineActivationCode; } - async deactivateSubscription({ - username, - license, - }: { - username: string; - license: Pick; - }): Promise { - 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,