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 variable module (#468)

Co-authored-by: rajdip-b <[email protected]>
  • Loading branch information
Nil2000 and rajdip-b authored Oct 17, 2024
1 parent 5a10e39 commit d970aff
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 7 deletions.
44 changes: 39 additions & 5 deletions apps/api/src/variable/service/variable.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,12 @@ export class VariableService {
},
versions: {
select: {
environmentId: true,
environment: {
select: {
id: true,
slug: true
}
},
value: true
}
}
Expand Down Expand Up @@ -244,7 +249,12 @@ export class VariableService {
},
select: {
id: true,
environmentId: true,
environment: {
select: {
id: true,
slug: true
}
},
value: true,
version: true
}
Expand Down Expand Up @@ -506,6 +516,15 @@ export class VariableService {
where: {
environmentId
},
select: {
value: true,
environment: {
select: {
id: true,
slug: true
}
}
},
orderBy: {
version: 'desc'
},
Expand Down Expand Up @@ -568,11 +587,20 @@ export class VariableService {
id: true,
name: true
}
},
versions: {
select: {
environment: {
select: {
id: true,
slug: true
}
}
}
}
},
skip: page * limit,
take: limitMaxItemsPerPage(limit),

orderBy: {
[sort]: order
}
Expand All @@ -586,6 +614,7 @@ export class VariableService {
environment: {
name: Environment['name']
id: Environment['id']
slug: Environment['slug']
}
value: VariableVersion['value']
version: VariableVersion['version']
Expand Down Expand Up @@ -619,6 +648,9 @@ export class VariableService {
},
orderBy: {
version: 'desc'
},
include: {
environment: true
}
})

Expand All @@ -628,7 +660,8 @@ export class VariableService {
variablesWithEnvironmentalValues.get(variable.id).values.push({
environment: {
id: latestVersion.environmentId,
name: envIds.get(latestVersion.environmentId)
name: envIds.get(latestVersion.environmentId),
slug: latestVersion.environment.slug
},
value: latestVersion.value,
version: latestVersion.version
Expand All @@ -640,7 +673,8 @@ export class VariableService {
{
environment: {
id: latestVersion.environmentId,
name: envIds.get(latestVersion.environmentId)
name: envIds.get(latestVersion.environmentId),
slug: latestVersion.environment.slug
},
value: latestVersion.value,
version: latestVersion.version
Expand Down
6 changes: 6 additions & 0 deletions apps/api/src/variable/variable.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,15 @@ describe('Variable Controller Tests', () => {
const variableVersion = await prisma.variableVersion.findMany({
where: {
variableId: variable1.id
},
include: {
environment: true
}
})

expect(variableVersion.length).toBe(1)
expect(variableVersion[0].environment.id).toBe(environment1.id)
expect(variableVersion[0].environment.slug).toBe(environment1.slug)
})

it('should create a new version if the value is updated', async () => {
Expand Down Expand Up @@ -596,6 +601,7 @@ describe('Variable Controller Tests', () => {
expect(values.length).toBe(1)
expect(values[0].value).toBe('Variable 1 value')
expect(values[0].environment.id).toBe(environment1.id)
expect(values[0].environment.slug).toBe(environment1.slug)
expect(variable.id).toBe(variable1.id)
expect(variable.name).toBe('Variable 1')

Expand Down
9 changes: 9 additions & 0 deletions packages/api-client/src/types/variable.types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export interface Variable {
{
value: string
environmentId: string
environment: {
id: string
slug: string
}
}
]
}
Expand Down Expand Up @@ -50,6 +54,10 @@ export interface UpdateVariableResponse {
{
value: string
environmentId: string
environment: {
id: string
slug: string
}
}
]
}
Expand Down Expand Up @@ -87,6 +95,7 @@ export interface GetAllVariablesOfProjectResponse
environment: {
id: string
name: string
slug: string
}
value: string
version: number
Expand Down
9 changes: 7 additions & 2 deletions packages/api-client/tests/variable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ describe('Get Variable Tests', () => {
expect(variable.data.name).toBe('Variable 2')
expect(variable.data.versions.length).toBe(1)
expect(variable.data.versions[0].value).toBe('Variable 2 value')
expect(variable.data.versions[0].environmentId).toBe(environment.id)
expect(variable.data.versions[0].environment.id).toBe(environment.id)
expect(variable.data.versions[0].environment.slug).toBe(environment.slug)

// Delete the variable
const deleteVariable = await variableController.deleteVariable(
Expand Down Expand Up @@ -164,9 +165,12 @@ describe('Get Variable Tests', () => {
)
expect(updateVariable.data.updatedVersions.length).toBe(1)
expect(updateVariable.data.updatedVersions[0].value).toBe('1234')
expect(updateVariable.data.updatedVersions[0].environmentId).toBe(
expect(updateVariable.data.updatedVersions[0].environment.id).toBe(
environment.id
)
expect(updateVariable.data.updatedVersions[0].environment.slug).toBe(
environment.slug
)
})

// Roll back a variable
Expand Down Expand Up @@ -222,6 +226,7 @@ describe('Get Variable Tests', () => {
expect(value).toHaveProperty('environment')
expect(value.environment).toHaveProperty('id')
expect(value.environment).toHaveProperty('name')
expect(value.environment).toHaveProperty('slug')
expect(value).toHaveProperty('value')
expect(value).toHaveProperty('version')
})
Expand Down

0 comments on commit d970aff

Please sign in to comment.