Skip to content

Commit

Permalink
fix(api,api-client): Add environmentSlug in multiple places across th…
Browse files Browse the repository at this point in the history
…e secret module (#509)
  • Loading branch information
anudeeps352 authored Oct 25, 2024
1 parent 534a231 commit ee58f07
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 5 deletions.
10 changes: 10 additions & 0 deletions apps/api/src/secret/secret.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand All @@ -371,6 +378,9 @@ describe('Secret Controller Tests', () => {
where: {
secretId: secret1.id,
environmentId: environment1.id
},
include: {
environment: true
}
})

Expand Down
43 changes: 40 additions & 3 deletions apps/api/src/secret/service/secret.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,12 @@ export class SecretService {
},
versions: {
select: {
environmentId: true,
environment: {
select: {
id: true,
slug: true
}
},
value: true
}
}
Expand Down Expand Up @@ -252,7 +257,12 @@ export class SecretService {
},
select: {
id: true,
environmentId: true,
environment: {
select: {
id: true,
slug: true
}
},
value: true,
version: true
}
Expand Down Expand Up @@ -514,7 +524,15 @@ export class SecretService {
orderBy: {
version: 'desc'
},
take: 1
take: 1,
include: {
environment: {
select: {
id: true,
slug: true
}
}
}
}
}
})
Expand Down Expand Up @@ -648,6 +666,17 @@ export class SecretService {
id: true,
name: true
}
},
versions: {
select: {
environment: {
select: {
name: true,
id: true,
slug: true
}
}
}
}
},
skip: page * limit,
Expand Down Expand Up @@ -699,6 +728,14 @@ export class SecretService {
},
orderBy: {
version: 'desc'
},
include: {
environment: {
select: {
id: true,
slug: true
}
}
}
})

Expand Down
9 changes: 9 additions & 0 deletions packages/api-client/src/types/secret.types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export interface Secret {
id?: string
environmentId: string
value: string
environment: {
id: string
slug: string
}
}
]
}
Expand Down Expand Up @@ -48,6 +52,10 @@ export interface UpdateSecretResponse {
{
id?: string
environmentId: string
environment: {
id: string
slug: string
}
value: string
}
]
Expand Down Expand Up @@ -83,6 +91,7 @@ export interface GetAllSecretsOfProjectResponse
environment: {
id: string
name: string
slug: string
}
value: string
version: number
Expand Down
5 changes: 3 additions & 2 deletions packages/api-client/tests/secret.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,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 environmentSlug: string | null

beforeAll(async () => {
//Create the user's workspace
Expand Down Expand Up @@ -115,6 +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(environmentSlug)
expect(secret.error).toBe(null)

// Delete the secret
Expand Down Expand Up @@ -244,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 },
{ secretSlug, environmentSlug},
{ 'x-e2e-user-email': email }
)
expect(revisions.data.items.length).toBe(1)
Expand Down

0 comments on commit ee58f07

Please sign in to comment.