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

feat(api-client): Create controller for Variable module #395

Merged
merged 12 commits into from
Aug 16, 2024
Merged
Prev Previous commit
Next Next commit
Resolved Issues
  • Loading branch information
vr-varad committed Jul 28, 2024
commit 435050f0dae39f6114df9c34e10931139a4bf499
4 changes: 2 additions & 2 deletions packages/api-client/src/controllers/variable/variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default class VariableController {
static async getAllVariablesOfProject(
request: GetAllVariablesOfProjectRequest,
headers: Record<string, string>
): Promise<GetAllVariablesOfProjectResponse> {
): Promise<GetAllVariablesOfProjectResponse[]> {
let url = `/api/variable/${request.projectId}`
request.page && (url += `page=${request.page}&`)
request.limit && (url += `limit=${request.limit}&`)
Expand All @@ -73,7 +73,7 @@ export default class VariableController {
static async getAllVariablesOfEnvironment(
request: GetAllVariablesOfEnvironmentRequest,
headers: Record<string, string>
): Promise<GetAllVariablesOfEnvironmentResponse> {
): Promise<GetAllVariablesOfEnvironmentResponse[]> {
let url = `/api/variable/${request.projectId}/${request.environmentId}`
request.page && (url += `page=${request.page}&`)
request.limit && (url += `limit=${request.limit}&`)
Expand Down
44 changes: 16 additions & 28 deletions packages/api-client/src/types/variable.types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,27 @@ export interface GetAllVariablesOfProjectRequest {
}

export interface GetAllVariablesOfProjectResponse {
items: {
variable: {
id: string
name: string
createdAt: string
updatedAt: string
note: string | null
lastUpdatedById: string
projectId: string
project: {
workspaceId: string
lastUpdatedBy: {
id: string
name: string
}
}
values: {
environment: {
id: string
name: string
}
versions: [
{
value: string
environmentId: string
}
]
}[]
value: string
version: number
}
}

export interface GetAllVariablesOfEnvironmentRequest {
Expand All @@ -109,22 +112,7 @@ export interface GetAllVariablesOfEnvironmentRequest {
}

export interface GetAllVariablesOfEnvironmentResponse {
items: {
id: string
name: string
createdAt: string
updatedAt: string
note: string | null
lastUpdatedById: string
projectId: string
project: {
workspaceId: string
}
versions: [
{
value: string
environmentId: string
}
]
}[]
name: string
value: string
isPlaintext: boolean
}
64 changes: 62 additions & 2 deletions packages/api-client/tests/variable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,56 @@ describe('Get Variable Tests', () => {

// Get all the variables of project
it('should get all variables of project', async () => {
const variables: any = await VariableController.getAllVariablesOfProject(
const response: any = await VariableController.getAllVariablesOfProject(
{ projectId },
{ 'x-e2e-user-email': email }
)
expect(variables.length).toBe(1)
expect(response.length).toBe(1)
const variable1 = response[0]
const variable = variable1.variable
const values = variable1.values
expect(variable).toHaveProperty('id')
expect(typeof variable.id).toBe('string')

expect(variable).toHaveProperty('name')
expect(typeof variable.name).toBe('string')

expect(variable).toHaveProperty('createdAt')
expect(typeof variable.createdAt).toBe('string')

expect(variable).toHaveProperty('updatedAt')
expect(typeof variable.updatedAt).toBe('string')

expect(variable).toHaveProperty('note')
expect(typeof variable.note === 'string' || variable.note === null).toBe(
true
)

expect(variable).toHaveProperty('lastUpdatedById')
expect(typeof variable.lastUpdatedById).toBe('string')

expect(variable).toHaveProperty('projectId')
expect(typeof variable.projectId).toBe('string')

expect(variable).toHaveProperty('lastUpdatedBy')
expect(variable.lastUpdatedBy).toHaveProperty('id')
expect(typeof variable.lastUpdatedBy.id).toBe('string')
expect(variable.lastUpdatedBy).toHaveProperty('name')
expect(typeof variable.lastUpdatedBy.name).toBe('string')

values.forEach((value) => {
expect(value).toHaveProperty('environment')
expect(value.environment).toHaveProperty('id')
expect(typeof value.environment.id).toBe('string')
expect(value.environment).toHaveProperty('name')
expect(typeof value.environment.name).toBe('string')

expect(value).toHaveProperty('value')
expect(typeof value.value).toBe('string')

expect(value).toHaveProperty('version')
expect(typeof value.version).toBe('number')
})
})

// Get all variables for an environment
Expand All @@ -139,7 +184,22 @@ describe('Get Variable Tests', () => {
},
{ 'x-e2e-user-email': email }
)

expect(variables.length).toBe(1)
variables.forEach((variable) => {
expect(variable).toHaveProperty('name')
expect(typeof variable.name).toBe('string')

expect(variable).toHaveProperty('value')
expect(typeof variable.value).toBe('string')

expect(variable).toHaveProperty('isPlaintext')
expect(typeof variable.isPlaintext).toBe('boolean')
})
const variable1 = variables[0]
expect(variable1.name).toBe('UpdatedVariable 1')
expect(variable1.value).toBe('Variable 1 value')
expect(variable1.isPlaintext).toBe(true)
})

// Delete a variable
Expand Down
Loading