Skip to content

Commit

Permalink
chore(api-client): Removed try-catch from tests in environment
Browse files Browse the repository at this point in the history
  • Loading branch information
rajdip-b committed Jul 27, 2024
1 parent d7d0190 commit 6ce7865
Showing 1 changed file with 101 additions and 137 deletions.
238 changes: 101 additions & 137 deletions packages/api-client/tests/environment.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,39 @@ describe('Get Environments Tests', () => {
let environment: any

beforeAll(async () => {
try {
//Create the user's workspace
const workspaceResponse = (await client.post(
'/api/workspace',
{
name: 'My Workspace'
},
{
'x-e2e-user-email': email
}
)) as any
//Create the user's workspace
const workspaceResponse = (await client.post(
'/api/workspace',
{
name: 'My Workspace'
},
{
'x-e2e-user-email': email
}
)) as any

workspaceId = workspaceResponse.id
workspaceId = workspaceResponse.id

// Create a project
const projectResponse = (await client.post(
`/api/project/${workspaceId}`,
{
name: 'Project',
storePrivateKey: true
},
{
'x-e2e-user-email': email
}
)) as any
// Create a project
const projectResponse = (await client.post(
`/api/project/${workspaceId}`,
{
name: 'Project',
storePrivateKey: true
},
{
'x-e2e-user-email': email
}
)) as any

projectId = projectResponse.id
} catch (error) {
console.error(error)
process.exit(1)
}
projectId = projectResponse.id
})

afterAll(async () => {
try {
// Delete the workspace
await client.delete(`/api/workspace/${workspaceId}`, {
'x-e2e-user-email': email
})
} catch (error) {
console.error(error)
process.exit(1)
}
// Delete the workspace
await client.delete(`/api/workspace/${workspaceId}`, {
'x-e2e-user-email': email
})
})

beforeEach(async () => {
Expand All @@ -76,106 +66,85 @@ describe('Get Environments Tests', () => {
})

it('should return a list of environments', async () => {
try {
const environments =
await EnvironmentController.getAllEnvironmentsOfProject(
{
projectId
},
{
'x-e2e-user-email': email
}
)

expect(environments).toHaveLength(2)
expect(environments[0].name).toBe('Default')
} catch (error) {
console.error(error)
process.exit(1)
}
const environments =
await EnvironmentController.getAllEnvironmentsOfProject(
{
projectId
},
{
'x-e2e-user-email': email
}
)

expect(environments).toHaveLength(2)
expect(environments[0].name).toBe('Default')
})

it('should be able to fetch environment by ID', async () => {
try {
const environmentResponse =
await EnvironmentController.getEnvironmentById(
{
id: environment.id
},
{
'x-e2e-user-email': email
}
)

expect(environmentResponse.id).toBe(environment.id)
expect(environmentResponse.name).toBe('Dev')
} catch (error) {
console.error(error)
process.exit(1)
}
const environmentResponse = await EnvironmentController.getEnvironmentById(
{
id: environment.id
},
{
'x-e2e-user-email': email
}
)

expect(environmentResponse.id).toBe(environment.id)
expect(environmentResponse.name).toBe('Dev')
})

it('should be able to create an environment', async () => {
try {
const createEnvironmentResponse =
await EnvironmentController.createEnvironment(
{
projectId,
name: 'Prod'
},
{
'x-e2e-user-email': email
}
)

expect(createEnvironmentResponse.name).toBe('Prod')

const fetchEnvironmentResponse = (await client.get(
`/api/environment/${createEnvironmentResponse.id}`,
const createEnvironmentResponse =
await EnvironmentController.createEnvironment(
{
projectId,
name: 'Prod'
},
{
'x-e2e-user-email': email
}
)) as any
)

expect(fetchEnvironmentResponse.name).toBe('Prod')
expect(createEnvironmentResponse.name).toBe('Prod')

// Delete the environment
await client.delete(`/api/environment/${createEnvironmentResponse.id}`, {
const fetchEnvironmentResponse = (await client.get(
`/api/environment/${createEnvironmentResponse.id}`,
{
'x-e2e-user-email': email
})
} catch (error) {
console.error(error)
process.exit(1)
}
}
)) as any

expect(fetchEnvironmentResponse.name).toBe('Prod')

// Delete the environment
await client.delete(`/api/environment/${createEnvironmentResponse.id}`, {
'x-e2e-user-email': email
})
})

it('should be able to update an environment', async () => {
try {
const updateEnvironmentResponse =
await EnvironmentController.updateEnvironment(
{
id: environment.id,
name: 'Prod'
},
{
'x-e2e-user-email': email
}
)

expect(updateEnvironmentResponse.name).toBe('Prod')

const fetchEnvironmentResponse = (await client.get(
`/api/environment/${environment.id}`,
const updateEnvironmentResponse =
await EnvironmentController.updateEnvironment(
{
id: environment.id,
name: 'Prod'
},
{
'x-e2e-user-email': email
}
)) as any
)

expect(updateEnvironmentResponse.name).toBe('Prod')

const fetchEnvironmentResponse = (await client.get(
`/api/environment/${environment.id}`,
{
'x-e2e-user-email': email
}
)) as any

expect(fetchEnvironmentResponse.name).toBe('Prod')
} catch (error) {
console.error(error)
process.exit(1)
}
expect(fetchEnvironmentResponse.name).toBe('Prod')
})

it('should be able to delete an environment', async () => {
Expand All @@ -190,31 +159,26 @@ describe('Get Environments Tests', () => {
}
)) as any

try {
await EnvironmentController.deleteEnvironment(
await EnvironmentController.deleteEnvironment(
{
id: createEnvironmentResponse.id
},
{
'x-e2e-user-email': email
}
)

// Check if the environment is deleted
const environments =
await EnvironmentController.getAllEnvironmentsOfProject(
{
id: createEnvironmentResponse.id
projectId
},
{
'x-e2e-user-email': email
}
)

// Check if the environment is deleted
const environments =
await EnvironmentController.getAllEnvironmentsOfProject(
{
projectId
},
{
'x-e2e-user-email': email
}
)

expect(environments).toHaveLength(2)
} catch (error) {
console.error(error)
process.exit(1)
}
expect(environments).toHaveLength(2)
})
})

0 comments on commit 6ce7865

Please sign in to comment.