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/requestLine.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const registerDevice: RequestHandler<object, unknown, RegisterDeviceBody>
timestamp: new Date().toISOString(),
});

res.status(301).json({
res.status(410).json({
message: 'This endpoint is deprecated. Use POST /auth/sign-in/anonymous for registration.',
endpoint: `${authUrl}/sign-in/anonymous`,
});
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
4 changes: 2 additions & 2 deletions tests/integration/requestLine.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ const getTestToken = async () => {

describe('Request Line Endpoint', () => {
describe('Device Registration (Legacy Endpoint)', () => {
it('should return 301 redirect for legacy registration endpoint', async () => {
it('should return 410 Gone for legacy registration endpoint', async () => {
const response = await request.post('/request/register').send({ deviceId: 'test-uuid' });

expect(response.status).toBe(301);
expect(response.status).toBe(410);
expect(response.body.message).toMatch(/deprecated/i);
expect(response.body.endpoint).toMatch(/sign-in\/anonymous/);
});
Expand Down
81 changes: 81 additions & 0 deletions tests/unit/controllers/requestLine.registerDevice.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { registerDevice } from '../../../apps/backend/controllers/requestLine.controller';
import type { Request, Response } from 'express';

function mockReq(overrides: Partial<Request> = {}): Request {
return {
method: 'POST',
originalUrl: '/request/register',
ip: '127.0.0.1',
get: jest.fn().mockReturnValue('test-agent'),
body: { deviceId: 'some-device-id' },
...overrides,
} as unknown as Request;
}

function mockRes(): Response & { _status: number; _json: unknown } {
const res = {
_status: 0,
_json: undefined as unknown,
status(code: number) {
res._status = code;
return res;
},
json(body: unknown) {
res._json = body;
return res;
},
};
return res as unknown as Response & { _status: number; _json: unknown };
}

describe('registerDevice', () => {
const originalEnv = process.env.BETTER_AUTH_URL;

afterEach(() => {
if (originalEnv !== undefined) {
process.env.BETTER_AUTH_URL = originalEnv;
} else {
delete process.env.BETTER_AUTH_URL;
}
});

it('returns 410 Gone for the deprecated endpoint', async () => {
process.env.BETTER_AUTH_URL = 'https://api.wxyc.org/auth';

const req = mockReq();
const res = mockRes();
const next = jest.fn();

await registerDevice(req, res as unknown as Response, next);

expect(res._status).toBe(410);
});

it('includes deprecation message and replacement endpoint', async () => {
process.env.BETTER_AUTH_URL = 'https://api.wxyc.org/auth';

const req = mockReq();
const res = mockRes();
const next = jest.fn();

await registerDevice(req, res as unknown as Response, next);

expect(res._json).toEqual({
message: 'This endpoint is deprecated. Use POST /auth/sign-in/anonymous for registration.',
endpoint: 'https://api.wxyc.org/auth/sign-in/anonymous',
});
});

it('falls back to localhost auth URL when BETTER_AUTH_URL is unset', async () => {
delete process.env.BETTER_AUTH_URL;

const req = mockReq();
const res = mockRes();
const next = jest.fn();

await registerDevice(req, res as unknown as Response, next);

expect(res._status).toBe(410);
expect((res._json as { endpoint: string }).endpoint).toBe('http://localhost:8082/auth/sign-in/anonymous');
});
});