Skip to content
Open
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
2 changes: 1 addition & 1 deletion apps/backend/controllers/djs.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const addToBin: RequestHandler<object, unknown, binBody> = async (req, re
};
try {
const added_bin_item = await DJService.addToBin(bin_entry);
res.status(200).json(added_bin_item);
res.status(201).json(added_bin_item);
} catch (e) {
console.error('Server error: Failed to insert into bin');
console.error(e);
Expand Down
6 changes: 3 additions & 3 deletions apps/backend/controllers/flowsheet.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export const addEntry: RequestHandler = async (req: Request<object, object, FSEn
}).catch((err) => console.error('[Flowsheet] Metadata fetch failed:', err));
}

res.status(200).json(completedEntry);
res.status(201).json(completedEntry);
} else if (
body.album_title === undefined ||
body.artist_name === undefined ||
Expand Down Expand Up @@ -210,7 +210,7 @@ export const addEntry: RequestHandler = async (req: Request<object, object, FSEn
}).catch((err) => console.error('[Flowsheet] Metadata fetch failed:', err));
}

res.status(200).json(completedEntry);
res.status(201).json(completedEntry);
}
} catch (e) {
console.error('Error: Failed to add track to flowsheet');
Expand All @@ -229,7 +229,7 @@ export const addEntry: RequestHandler = async (req: Request<object, object, FSEn
};
try {
const completedEntry: FSEntry = await flowsheet_service.addTrack(fsEntry);
res.status(200).json(completedEntry);
res.status(201).json(completedEntry);
} catch (e) {
console.error('Error: Failed to add message to flowsheet');
console.error(e);
Expand Down
10 changes: 5 additions & 5 deletions apps/backend/controllers/library.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const addAlbum: RequestHandler = async (req: Request<object, object, NewA
};

const inserted_album: Album = await libraryService.insertAlbum(new_album);
res.status(200).json(inserted_album);
res.status(201).json(inserted_album);
} catch (e) {
console.error('Error: Could not insert new album');
console.error(e);
Expand Down Expand Up @@ -142,7 +142,7 @@ export const addArtist: RequestHandler = async (req: Request<object, object, New
};

const response: Artist = await libraryService.insertArtist(new_artist);
res.status(200);
res.status(201);
res.send(response);
} catch (e) {
console.error('Error: Failed to add new artist');
Expand Down Expand Up @@ -170,7 +170,7 @@ export const addRotation: RequestHandler<object, unknown, NewRotationRelease> =
} else {
try {
const rotationRelease: RotationRelease = await libraryService.addToRotation(req.body);
res.status(200).json(rotationRelease);
res.status(201).json(rotationRelease);
} catch (e) {
console.error(e);
next(e);
Expand Down Expand Up @@ -228,7 +228,7 @@ export const addFormat: RequestHandler = async (req, res, next) => {
};

const insertion = await libraryService.insertFormat(newFormat);
res.status(200).json(insertion);
res.status(201).json(insertion);
} catch (e) {
console.error('Failed to add new format');
console.error(e);
Expand Down Expand Up @@ -258,7 +258,7 @@ export const addGenre: RequestHandler = async (req, res, next) => {

const insertion = await libraryService.insertGenre(newGenre);

res.status(200).json(insertion);
res.status(201).json(insertion);
} catch (e) {
console.error('Failed to add new genre');
console.error(e);
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/controllers/schedule.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const addToSchedule: RequestHandler = async (req: Request<object, object,
const { body } = req;
try {
const response = await ScheduleService.addToSchedule(body);
res.status(200).json(response);
res.status(201).json(response);
} catch (e) {
console.error('Error adding to schedule');
console.error(e);
Expand Down
32 changes: 16 additions & 16 deletions tests/integration/flowsheet.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ describe('Add to Flowsheet', () => {
track_title: 'Carry the Zero',
// record_label: 'Warner Bros',
})
.expect(200);
.expect(201);

expect(res.body).toBeDefined();
expect(res.body.album_title).toEqual('Keep it Like a Secret');
Expand All @@ -182,7 +182,7 @@ describe('Add to Flowsheet', () => {
track_title: 'Carry the Zero',
rotation_id: 1,
})
.expect(200);
.expect(201);

expect(res.body).toBeDefined();
expect(res.body.album_title).toEqual('Keep it Like a Secret');
Expand All @@ -197,7 +197,7 @@ describe('Add to Flowsheet', () => {
track_title: 'Carry the Zero',
record_label: 'Warner Bros',
})
.expect(200);
.expect(201);

expect(res.body.album_title).toEqual('Keep it Like a Secret');
expect(res.body.track_title).toEqual('Carry the Zero');
Expand All @@ -213,7 +213,7 @@ describe('Add to Flowsheet', () => {
track_title: 'Carry the Zero',
request_flag: true,
})
.expect(200);
.expect(201);

expect(res.body).toBeDefined();
expect(res.body.album_title).toEqual('Keep it Like a Secret');
Expand All @@ -229,7 +229,7 @@ describe('Add to Flowsheet', () => {
album_title: 'Keep it Like a Secret',
track_title: 'Carry the Zero',
})
.expect(200);
.expect(201);

expect(res.body).toBeDefined();
expect(res.body.album_title).toEqual('Keep it Like a Secret');
Expand All @@ -246,7 +246,7 @@ describe('Add to Flowsheet', () => {
track_title: 'Carry the Zero',
record_label: 'Warner Bros',
})
.expect(200);
.expect(201);

expect(res.body).toBeDefined();
expect(res.body.album_title).toEqual('Keep it Like a Secret');
Expand All @@ -264,7 +264,7 @@ describe('Add to Flowsheet', () => {
track_title: 'Carry the Zero',
request_flag: true,
})
.expect(200);
.expect(201);

expect(res.body).toBeDefined();
expect(res.body.album_title).toEqual('Keep it Like a Secret');
Expand All @@ -278,7 +278,7 @@ describe('Add to Flowsheet', () => {
.send({
message: 'Test Message',
})
.expect(200);
.expect(201);

expect(res.body).toBeDefined();
expect(res.body.message).toEqual('Test Message');
Expand Down Expand Up @@ -477,7 +477,7 @@ describe('Retrieve Now Playing', () => {
album_id: 1, //Built to Spill - Keep it Like a Secret
track_title: 'Carry the Zero',
})
.expect(200);
.expect(201);
});

afterEach(async () => {
Expand All @@ -500,7 +500,7 @@ describe('Retrieve Now Playing', () => {
album_id: 2, //Ravyn Lenae - Crush
track_title: 'Venom',
})
.expect(200);
.expect(201);

res = await request.get('/flowsheet/latest').expect(200);
expect(res.body).toBeDefined();
Expand All @@ -522,7 +522,7 @@ describe('Shift Flowsheet Entries', () => {
album_id: 1, //Built to Spill - Keep it Like a Secret
track_title: 'Carry the Zero',
})
.expect(200);
.expect(201);

await request
.post('/flowsheet')
Expand All @@ -531,7 +531,7 @@ describe('Shift Flowsheet Entries', () => {
album_id: 2, //Ravyn Lenae - Crush
track_title: 'Venom',
})
.expect(200);
.expect(201);

await request
.post('/flowsheet')
Expand All @@ -540,7 +540,7 @@ describe('Shift Flowsheet Entries', () => {
album_id: 3, //Jockstrap - I Love You Jennifer B
track_title: 'Debra',
})
.expect(200);
.expect(201);
});

afterEach(async () => {
Expand Down Expand Up @@ -685,7 +685,7 @@ describe('Retrieve Playlist Object', () => {
album_id: 3, //Jockstrap - I Love You Jennifer B
track_title: 'Debra',
})
.expect(200);
.expect(201);

await fls_util.leave_show(global.primary_dj_id, global.access_token);
});
Expand Down Expand Up @@ -735,7 +735,7 @@ describe('V2 Playlist - Discriminated Union Format', () => {
album_id: 3, //Jockstrap - I Love You Jennifer B
track_title: 'Debra',
})
.expect(200);
.expect(201);

await fls_util.leave_show(global.primary_dj_id, global.access_token);
});
Expand Down Expand Up @@ -793,7 +793,7 @@ describe('V1 API - entry_type field', () => {
album_id: 1,
track_title: 'Carry the Zero',
})
.expect(200);
.expect(201);

// V1 response should now include entry_type (additive change)
expect(addRes.body.entry_type).toBe('track');
Expand Down
60 changes: 60 additions & 0 deletions tests/unit/controllers/create-status-codes.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { Request, Response, NextFunction } from 'express';

jest.mock('../../../apps/backend/services/djs.service');
jest.mock('../../../apps/backend/services/schedule.service');

import * as DJService from '../../../apps/backend/services/djs.service';
import * as ScheduleService from '../../../apps/backend/services/schedule.service';
import { addToBin } from '../../../apps/backend/controllers/djs.controller';
import { addToSchedule } from '../../../apps/backend/controllers/schedule.controller';

function mockReqResNext(body: Record<string, unknown> = {}) {
const req = { body } as unknown as Request;
const statusMock = jest.fn().mockReturnThis();
const jsonMock = jest.fn().mockReturnThis();
const sendMock = jest.fn().mockReturnThis();
const res = {
status: statusMock,
json: jsonMock,
send: sendMock,
} as unknown as Response;
const next = jest.fn() as unknown as NextFunction;
return { req, res, next, statusMock, jsonMock, sendMock };
}

describe('create endpoints return 201', () => {
describe('addToBin', () => {
it('should return 201 when a bin entry is created', async () => {
const created = { id: 1, dj_id: 'dj-1', album_id: 10, track_title: null };
(DJService.addToBin as jest.Mock).mockResolvedValue(created);

const { req, res, next, statusMock, jsonMock } = mockReqResNext({
dj_id: 'dj-1',
album_id: 10,
});

await addToBin(req, res, next);

expect(statusMock).toHaveBeenCalledWith(201);
expect(jsonMock).toHaveBeenCalledWith(created);
});
});

describe('addToSchedule', () => {
it('should return 201 when a schedule entry is created', async () => {
const created = { id: 1, day: 'Monday', start_time: '10:00', end_time: '12:00' };
(ScheduleService.addToSchedule as jest.Mock).mockResolvedValue(created);

const { req, res, next, statusMock, jsonMock } = mockReqResNext({
day: 'Monday',
start_time: '10:00',
end_time: '12:00',
});

await addToSchedule(req, res, next);

expect(statusMock).toHaveBeenCalledWith(201);
expect(jsonMock).toHaveBeenCalledWith(created);
});
});
});