Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api,api-client): Add environmentSlug in multiple places across the variable module #468

Merged
merged 30 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
eb73d8f
fix(api,api-client) :Add environmentSlug in multiple places across th…
Nil2000 Sep 26, 2024
beaf876
Merge branch 'develop' into d-431
Nil2000 Sep 26, 2024
298221d
Some typo
Nil2000 Sep 26, 2024
5abb06d
Some typo
Nil2000 Sep 26, 2024
e66683e
Fixed few typos:2
Nil2000 Sep 29, 2024
6a3f063
Fixed few typos:3
Nil2000 Sep 29, 2024
f091bb6
Testing typos
Nil2000 Sep 29, 2024
1d8bf61
Testing typos
Nil2000 Sep 29, 2024
6ceb9a0
Merge branch 'develop' into d-431
Nil2000 Sep 29, 2024
8d63588
Testing typo fix
Nil2000 Sep 29, 2024
d8c35ff
Merge branch 'd-431' of https://github.com/Nil2000/keyshade into d-431
Nil2000 Sep 29, 2024
d409add
fix(api,api-client) :Add environmentSlug in multiple places across th…
Nil2000 Sep 26, 2024
92b1712
Some typo
Nil2000 Sep 26, 2024
67279ce
Some typo
Nil2000 Sep 26, 2024
11e9148
Fixed few typos:2
Nil2000 Sep 29, 2024
6f27739
Fixed few typos:3
Nil2000 Sep 29, 2024
5cedec3
Testing typos
Nil2000 Sep 29, 2024
9663088
Testing typos
Nil2000 Sep 29, 2024
ea69bc2
Testing typo fix
Nil2000 Sep 29, 2024
7f83d64
fixed test error
rajdip-b Oct 13, 2024
0de10c2
reverted jest config
rajdip-b Oct 13, 2024
2d66a55
Merge branch 'develop' into d-431
Nil2000 Oct 13, 2024
e90d34f
Merge branch 'develop' into d-431
Nil2000 Oct 14, 2024
3dd3bca
Resolved Merge conflict
Nil2000 Oct 14, 2024
21d3c2a
Merge branch 'develop' into d-431
Nil2000 Oct 15, 2024
8b3be35
Merge branch 'd-431' of https://github.com/Nil2000/keyshade into d-431
Nil2000 Oct 15, 2024
f30df2b
Fixed some issues
Nil2000 Oct 16, 2024
0231e6e
Merge branch 'develop' into d-431
Nil2000 Oct 16, 2024
87e4da8
Fixed few more typos
Nil2000 Oct 17, 2024
4602ea6
Merge branch 'd-431' of https://github.com/Nil2000/keyshade into d-431
Nil2000 Oct 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 41 additions & 3 deletions apps/api/src/variable/service/variable.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ export class VariableService {
versions: {
select: {
environmentId: true,
environment: {
select: {
id: true,
slug: true
}
},
value: true
}
}
Expand Down Expand Up @@ -245,6 +251,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 +518,16 @@ export class VariableService {
where: {
environmentId
},
select: {
value: true,
environmentId: true,
environment: {
select: {
id: true,
slug: true
}
}
},
orderBy: {
version: 'desc'
},
Expand Down Expand Up @@ -568,11 +590,21 @@ export class VariableService {
id: true,
name: true
}
},
versions: {
select: {
environmentId: true,
environment: {
select: {
id: true,
slug: true
}
}
}
}
},
skip: page * limit,
take: limitMaxItemsPerPage(limit),

orderBy: {
[sort]: order
}
Expand All @@ -586,6 +618,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 +652,9 @@ export class VariableService {
},
orderBy: {
version: 'desc'
},
include: {
environment: true
}
})

Expand All @@ -628,7 +664,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 +677,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
8 changes: 8 additions & 0 deletions apps/api/src/variable/variable.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ describe('Variable Controller Tests', () => {
expect(body.projectId).toBe(project1.id)
expect(body.versions.length).toBe(1)
expect(body.versions[0].value).toBe('Variable 3 value')
// expect(body.versions[0].environment.id).toBe(environment2.id)
expect(body.versions[0].environment.slug).toBe(environment2.slug)
Nil2000 marked this conversation as resolved.
Show resolved Hide resolved

const variable = await prisma.variable.findUnique({
where: {
Expand Down Expand Up @@ -382,10 +384,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 +603,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: 9 additions & 0 deletions packages/api-client/tests/variable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ describe('Get Variable Tests', () => {
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)
Nil2000 marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -167,6 +169,12 @@ describe('Get Variable Tests', () => {
expect(updateVariable.data.updatedVersions[0].environmentId).toBe(
Nil2000 marked this conversation as resolved.
Show resolved Hide resolved
environment.id
)
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 +230,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
Loading