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: add missing "return" statements after errors #83

Merged
merged 5 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions src/service/router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,12 @@ describe('createRouter', () => {
});

describe('entity mappings', () => {
it("returns a 400 if no serviceId is provided", async () => {
const response = await request(app).post('/mapping/entity').send(JSON.stringify({}));
expect(response.status).toEqual(400);
expect(response.body).toEqual("Bad Request: 'serviceId' must be provided as part of the request body");
});

it("creates mapping reference dictionary from service-ids", async () => {
const mockEntitiesResponse = {
"items":
Expand Down
12 changes: 11 additions & 1 deletion src/service/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,13 @@ export async function createRouter(

if(serviceId === '') {
response.status(400).json("Bad Request: ':serviceId' must be provided as part of the path");
return;
}

const dependencies: string[] = Object.keys(request.body).length === 0 ? [] : request.body;
if(!dependencies || dependencies.length === 0) {
response.status(400).json("Bad Request: 'dependencies' must be provided as part of the request body");
return;
}

const serviceRelations : PagerDutyServiceDependency[] = [];
Expand Down Expand Up @@ -302,11 +304,13 @@ export async function createRouter(

if(serviceId === '') {
response.status(400).json("Bad Request: ':serviceId' must be provided as part of the path");
return;
}

const dependencies: string[] = Object.keys(request.body).length === 0 ? [] : request.body;
if(!dependencies || dependencies.length === 0) {
response.status(400).json("Bad Request: 'dependencies' must be provided as part of the request body");
return;
}

const serviceRelations : PagerDutyServiceDependency[] = [];
Expand Down Expand Up @@ -414,10 +418,12 @@ export async function createRouter(
await Promise.all(settings.map(async (setting) => {
if(setting.id === undefined || setting.value === undefined) {
response.status(400).json("Bad Request: 'id' and 'value' are required");
return;
}

if(!isValidSetting(setting.value)) {
response.status(400).json("Bad Request: 'value' is invalid. Valid options are 'backstage', 'pagerduty', 'both' or 'disabled'");
return;
}

await store.updateSetting(setting);
Expand Down Expand Up @@ -478,7 +484,8 @@ export async function createRouter(
const entity: PagerDutyEntityMapping = request.body;

if (!entity.serviceId) {
response.status(400).json("Bad Request: 'service_id' is required");
response.status(400).json("Bad Request: 'serviceId' must be provided as part of the request body");
return;
}

// Get all the entity mappings from the database
Expand Down Expand Up @@ -698,6 +705,7 @@ export async function createRouter(

if (escalationPolicyId === '') {
response.status(400).json("Bad Request: 'escalation_policy_ids[]' is required");
return;
}

const oncallUsers = await getOncallUsers(escalationPolicyId, account);
Expand Down Expand Up @@ -726,6 +734,7 @@ export async function createRouter(

if (serviceId === '') {
response.status(400).json("Bad Request: ':serviceId' must be provided as part of the path or 'integration_key' as a query parameter");
return;
}

const service = await getServiceById(serviceId, account);
Expand Down Expand Up @@ -787,6 +796,7 @@ export async function createRouter(

if (serviceId === '' || vendorId === '') {
response.status(400).json("Bad Request: ':serviceId' and ':vendorId' must be provided as part of the path");
return;
}

const integrationKey = await createServiceIntegration({
Expand Down
Loading