Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

Commit

Permalink
Handle terminating failed state
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Nguyen committed Mar 9, 2022
1 parent 2486cbf commit d8dd26d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1449,6 +1449,36 @@ Quisque egestas, eros nec feugiat venenatis, lorem turpis placerat tortor, ullam
}
});

it('should fail because the environment is in termination failed status', async () => {
// BUILD
const requestContext = {
principal: {
isExternalUser: false,
},
};
const existingEnv = {
id: 'abc',
name: 'exampleName',
envTypeId: 'exampleETI',
envTypeConfigId: 'exampleETCI',
status: environmentScStatus.TERMINATING_FAILED,
};

service.mustFind = jest.fn().mockResolvedValueOnce(existingEnv);

// OPERATE
try {
await service.delete(requestContext, { id: existingEnv.id });
expect.hasAssertions();
} catch (err) {
// CHECK
expect(service.boom.is(err, 'badRequest')).toBe(true);
expect(err.message).toContain(
`Workspace '${existingEnv.id}' can not be terminated while in ${environmentScStatus.TERMINATING_FAILED} status`,
);
}
});

it('should fail because the workflow failed to trigger', async () => {
// BUILD
const requestContext = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,13 @@ class EnvironmentScService extends Service {
throw this.boom.badRequest(`Workspace '${id}' is already being terminated`, true);
}

if (existingEnvironment.status === environmentScStatus.TERMINATING_FAILED) {
throw this.boom.badRequest(
`Workspace '${id}' can not be terminated while in ${environmentScStatus.TERMINATING_FAILED} status`,
true,
);
}

await this.update(requestContext, {
id,
rev: existingEnvironment.rev,
Expand Down

0 comments on commit d8dd26d

Please sign in to comment.