Skip to content

Commit

Permalink
Merge pull request #84 from PagerDuty/next
Browse files Browse the repository at this point in the history
release: 0.9.1
  • Loading branch information
t1agob authored Aug 2, 2024
2 parents 2420767 + b41c118 commit ac46701
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
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

0 comments on commit ac46701

Please sign in to comment.