From f95e7cdc6542bb5537909fa119139881ce12869d Mon Sep 17 00:00:00 2001 From: anudeeps352 Date: Mon, 21 Oct 2024 04:10:24 +0530 Subject: [PATCH 1/5] Add environmentSlug in multiple places --- apps/api/src/secret/secret.e2e.spec.ts | 10 +++++ apps/api/src/secret/secret.types.ts | 2 +- apps/api/src/secret/service/secret.service.ts | 42 +++++++++++++++++-- .../api-client/src/types/secret.types.d.ts | 9 ++++ packages/api-client/tests/secret.spec.ts | 6 ++- 5 files changed, 64 insertions(+), 5 deletions(-) diff --git a/apps/api/src/secret/secret.e2e.spec.ts b/apps/api/src/secret/secret.e2e.spec.ts index d7443775..da0487d9 100644 --- a/apps/api/src/secret/secret.e2e.spec.ts +++ b/apps/api/src/secret/secret.e2e.spec.ts @@ -209,6 +209,8 @@ describe('Secret Controller Tests', () => { expect(body.projectId).toBe(project1.id) expect(body.versions.length).toBe(1) expect(body.versions[0].value).not.toBe('Secret 2 value') + expect(body.versions[0].environment.id).toBe(environment1.id) + expect(body.versions[0].environment.slug).toBe(environment1.slug) }) it('should have created a secret version', async () => { @@ -341,10 +343,15 @@ describe('Secret Controller Tests', () => { const secretVersion = await prisma.secretVersion.findMany({ where: { secretId: secret1.id + }, + include: { + environment: true } }) expect(secretVersion.length).toBe(1) + expect(secretVersion[0].environment.id).toBe(environment1.id) + expect(secretVersion[0].environment.slug).toBe(environment1.slug) }) it('should create a new version if the value is updated', async () => { @@ -371,6 +378,9 @@ describe('Secret Controller Tests', () => { where: { secretId: secret1.id, environmentId: environment1.id + }, + include: { + environment: true } }) diff --git a/apps/api/src/secret/secret.types.ts b/apps/api/src/secret/secret.types.ts index 9a070f2d..ca48fca4 100644 --- a/apps/api/src/secret/secret.types.ts +++ b/apps/api/src/secret/secret.types.ts @@ -1,4 +1,4 @@ -import { Project, Secret, SecretVersion } from '@prisma/client' +import { Environment, Project, Secret, SecretVersion } from '@prisma/client' export interface SecretWithValue extends Secret { value: string diff --git a/apps/api/src/secret/service/secret.service.ts b/apps/api/src/secret/service/secret.service.ts index 4d84fd50..1b754cf9 100644 --- a/apps/api/src/secret/service/secret.service.ts +++ b/apps/api/src/secret/service/secret.service.ts @@ -126,7 +126,12 @@ export class SecretService { }, versions: { select: { - environmentId: true, + environment: { + select: { + id: true, + slug: true + } + }, value: true } } @@ -252,7 +257,12 @@ export class SecretService { }, select: { id: true, - environmentId: true, + environment: { + select: { + id: true, + slug: true + } + }, value: true, version: true } @@ -514,7 +524,15 @@ export class SecretService { orderBy: { version: 'desc' }, - take: 1 + take: 1, + include: { + environment: { + select: { + id: true, + slug: true + } + } + } } } }) @@ -648,6 +666,16 @@ export class SecretService { id: true, name: true } + }, + versions: { + select: { + environment: { + select: { + id: true, + slug: true + } + } + } } }, skip: page * limit, @@ -699,6 +727,14 @@ export class SecretService { }, orderBy: { version: 'desc' + }, + include: { + environment: { + select: { + id: true, + slug: true + } + } } }) diff --git a/packages/api-client/src/types/secret.types.d.ts b/packages/api-client/src/types/secret.types.d.ts index 1a173354..397d8b8f 100644 --- a/packages/api-client/src/types/secret.types.d.ts +++ b/packages/api-client/src/types/secret.types.d.ts @@ -18,6 +18,10 @@ export interface Secret { id?: string environmentId: string value: string + environment: { + id: string + slug: string + } } ] } @@ -48,6 +52,10 @@ export interface UpdateSecretResponse { { id?: string environmentId: string + environment: { + id: string + slug: string + } value: string } ] @@ -83,6 +91,7 @@ export interface GetAllSecretsOfProjectResponse environment: { id: string name: string + slug: string } value: string version: number diff --git a/packages/api-client/tests/secret.spec.ts b/packages/api-client/tests/secret.spec.ts index 38cd6966..2ff8db34 100644 --- a/packages/api-client/tests/secret.spec.ts +++ b/packages/api-client/tests/secret.spec.ts @@ -12,6 +12,7 @@ describe('Secret Controller Tests', () => { let workspaceSlug: string | null let environmentSlug: string | null let secretSlug: string | null + let environment beforeAll(async () => { //Create the user's workspace @@ -58,7 +59,8 @@ describe('Secret Controller Tests', () => { ) ).json()) as any - environmentSlug = createEnvironmentResponse.slug + environment = createEnvironmentResponse + environmentSlug = environment.slug }) afterAll(async () => { @@ -115,6 +117,8 @@ describe('Secret Controller Tests', () => { expect(secret.data.name).toBe('Secret 2') expect(secret.data.slug).toBeDefined() expect(secret.data.versions.length).toBe(1) + expect(secret.data.versions[0].environment.id).toBe(environment.id) + expect(secret.data.versions[0].environment.slug).toBe(environmentSlug) expect(secret.error).toBe(null) // Delete the secret From bd7ddba325e2db5efdbcc8d403c59728553fa4e2 Mon Sep 17 00:00:00 2001 From: anudeeps352 Date: Thu, 24 Oct 2024 00:02:25 +0530 Subject: [PATCH 2/5] removed unwanted imports --- apps/api/src/secret/secret.types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/api/src/secret/secret.types.ts b/apps/api/src/secret/secret.types.ts index ca48fca4..9a070f2d 100644 --- a/apps/api/src/secret/secret.types.ts +++ b/apps/api/src/secret/secret.types.ts @@ -1,4 +1,4 @@ -import { Environment, Project, Secret, SecretVersion } from '@prisma/client' +import { Project, Secret, SecretVersion } from '@prisma/client' export interface SecretWithValue extends Secret { value: string From 623b13f533cd5bcf82cb6a231499b3dc3d1cd368 Mon Sep 17 00:00:00 2001 From: anudeeps352 Date: Thu, 24 Oct 2024 22:09:51 +0530 Subject: [PATCH 3/5] removed envId comparison --- apps/api/src/secret/service/secret.service.ts | 1 + packages/api-client/tests/secret.spec.ts | 24 +++++++++---------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/apps/api/src/secret/service/secret.service.ts b/apps/api/src/secret/service/secret.service.ts index 1b754cf9..517b8364 100644 --- a/apps/api/src/secret/service/secret.service.ts +++ b/apps/api/src/secret/service/secret.service.ts @@ -671,6 +671,7 @@ export class SecretService { select: { environment: { select: { + name: true, id: true, slug: true } diff --git a/packages/api-client/tests/secret.spec.ts b/packages/api-client/tests/secret.spec.ts index 2ff8db34..f168f115 100644 --- a/packages/api-client/tests/secret.spec.ts +++ b/packages/api-client/tests/secret.spec.ts @@ -1,5 +1,6 @@ import { APIClient } from '../src/core/client' import SecretController from '../src/controllers/secret' +import { Environment } from '@api-client/types/environment.types' describe('Secret Controller Tests', () => { const backendUrl = process.env.BACKEND_URL @@ -10,9 +11,8 @@ describe('Secret Controller Tests', () => { const email = 'johndoe@example.com' let projectSlug: string | null let workspaceSlug: string | null - let environmentSlug: string | null let secretSlug: string | null - let environment + let environment: Environment beforeAll(async () => { //Create the user's workspace @@ -60,7 +60,6 @@ describe('Secret Controller Tests', () => { ).json()) as any environment = createEnvironmentResponse - environmentSlug = environment.slug }) afterAll(async () => { @@ -78,7 +77,7 @@ describe('Secret Controller Tests', () => { note: 'Secret 1 note', entries: [ { - environmentSlug, + environmentSlug: environment.slug, value: 'Secret 1 value' } ], @@ -105,7 +104,7 @@ describe('Secret Controller Tests', () => { note: 'Secret 2 note', entries: [ { - environmentSlug, + environmentSlug: environment.slug, value: 'Secret 1 value' } ], @@ -117,8 +116,7 @@ describe('Secret Controller Tests', () => { expect(secret.data.name).toBe('Secret 2') expect(secret.data.slug).toBeDefined() expect(secret.data.versions.length).toBe(1) - expect(secret.data.versions[0].environment.id).toBe(environment.id) - expect(secret.data.versions[0].environment.slug).toBe(environmentSlug) + expect(secret.data.versions[0].environment.slug).toBe(environment.slug) expect(secret.error).toBe(null) // Delete the secret @@ -155,7 +153,7 @@ describe('Secret Controller Tests', () => { entries: [ { value: 'Updated Secret 1 value', - environmentSlug + environmentSlug: environment.slug } ], secretSlug @@ -173,7 +171,7 @@ describe('Secret Controller Tests', () => { entries: [ { value: 'Secret 1 value', - environmentSlug + environmentSlug: environment.slug } ], secretSlug @@ -186,7 +184,7 @@ describe('Secret Controller Tests', () => { entries: [ { value: 'Updated Secret 1 value', - environmentSlug + environmentSlug: environment.slug } ], secretSlug @@ -195,7 +193,7 @@ describe('Secret Controller Tests', () => { ) const rollbackSecret = await secretController.rollbackSecret( - { secretSlug, environmentSlug, version: 1 }, + { secretSlug, environmentSlug: environment.slug, version: 1 }, { 'x-e2e-user-email': email } ) @@ -215,7 +213,7 @@ describe('Secret Controller Tests', () => { it('should get all secrets of an environment', async () => { const secrets: any = await secretController.getAllSecretsOfEnvironment( { - environmentSlug, + environmentSlug: environment.slug, projectSlug }, { 'x-e2e-user-email': email } @@ -248,7 +246,7 @@ describe('Secret Controller Tests', () => { it('should be able to fetch revisions of a secret', async () => { const revisions = await secretController.getRevisionsOfSecret( - { secretSlug, environmentSlug }, + { secretSlug, environmentSlug: environment.slug }, { 'x-e2e-user-email': email } ) expect(revisions.data.items.length).toBe(1) From 455905f4aca2d439cb96bad4c00c5ad778ada1fb Mon Sep 17 00:00:00 2001 From: Anudeep <94232161+anudeeps352@users.noreply.github.com> Date: Fri, 25 Oct 2024 17:20:12 +0530 Subject: [PATCH 4/5] removed environment and added environmentSLug --- packages/api-client/tests/secret.spec.ts | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/packages/api-client/tests/secret.spec.ts b/packages/api-client/tests/secret.spec.ts index f168f115..d2b193c1 100644 --- a/packages/api-client/tests/secret.spec.ts +++ b/packages/api-client/tests/secret.spec.ts @@ -1,6 +1,5 @@ import { APIClient } from '../src/core/client' import SecretController from '../src/controllers/secret' -import { Environment } from '@api-client/types/environment.types' describe('Secret Controller Tests', () => { const backendUrl = process.env.BACKEND_URL @@ -12,7 +11,7 @@ describe('Secret Controller Tests', () => { let projectSlug: string | null let workspaceSlug: string | null let secretSlug: string | null - let environment: Environment + let environmentSlug: string | null beforeAll(async () => { //Create the user's workspace @@ -59,7 +58,7 @@ describe('Secret Controller Tests', () => { ) ).json()) as any - environment = createEnvironmentResponse + environmentSlug = createEnvironmentResponse.slug }) afterAll(async () => { @@ -77,7 +76,7 @@ describe('Secret Controller Tests', () => { note: 'Secret 1 note', entries: [ { - environmentSlug: environment.slug, + environmentSlug, value: 'Secret 1 value' } ], @@ -104,7 +103,7 @@ describe('Secret Controller Tests', () => { note: 'Secret 2 note', entries: [ { - environmentSlug: environment.slug, + environmentSlug, value: 'Secret 1 value' } ], @@ -153,7 +152,7 @@ describe('Secret Controller Tests', () => { entries: [ { value: 'Updated Secret 1 value', - environmentSlug: environment.slug + environmentSlug } ], secretSlug @@ -171,7 +170,7 @@ describe('Secret Controller Tests', () => { entries: [ { value: 'Secret 1 value', - environmentSlug: environment.slug + environmentSlug } ], secretSlug @@ -184,7 +183,7 @@ describe('Secret Controller Tests', () => { entries: [ { value: 'Updated Secret 1 value', - environmentSlug: environment.slug + environmentSlug } ], secretSlug @@ -193,7 +192,7 @@ describe('Secret Controller Tests', () => { ) const rollbackSecret = await secretController.rollbackSecret( - { secretSlug, environmentSlug: environment.slug, version: 1 }, + { secretSlug, environmentSlug, version: 1 }, { 'x-e2e-user-email': email } ) @@ -213,7 +212,7 @@ describe('Secret Controller Tests', () => { it('should get all secrets of an environment', async () => { const secrets: any = await secretController.getAllSecretsOfEnvironment( { - environmentSlug: environment.slug, + environmentSlug, projectSlug }, { 'x-e2e-user-email': email } @@ -246,7 +245,7 @@ describe('Secret Controller Tests', () => { it('should be able to fetch revisions of a secret', async () => { const revisions = await secretController.getRevisionsOfSecret( - { secretSlug, environmentSlug: environment.slug }, + { secretSlug, environmentSlug}, { 'x-e2e-user-email': email } ) expect(revisions.data.items.length).toBe(1) From b37531d68aec475dc8ea61bf121e1ab182c9111c Mon Sep 17 00:00:00 2001 From: Anudeep <94232161+anudeeps352@users.noreply.github.com> Date: Fri, 25 Oct 2024 17:22:49 +0530 Subject: [PATCH 5/5] Update secret.spec.ts --- packages/api-client/tests/secret.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/api-client/tests/secret.spec.ts b/packages/api-client/tests/secret.spec.ts index d2b193c1..bdf71ea7 100644 --- a/packages/api-client/tests/secret.spec.ts +++ b/packages/api-client/tests/secret.spec.ts @@ -115,7 +115,7 @@ describe('Secret Controller Tests', () => { expect(secret.data.name).toBe('Secret 2') expect(secret.data.slug).toBeDefined() expect(secret.data.versions.length).toBe(1) - expect(secret.data.versions[0].environment.slug).toBe(environment.slug) + expect(secret.data.versions[0].environment.slug).toBe(environmentSlug) expect(secret.error).toBe(null) // Delete the secret