catalog-backend: add some missing location unit tests

Signed-off-by: MT Lewis <mtlewis@users.noreply.github.com>
This commit is contained in:
MT Lewis
2022-01-27 17:48:15 +00:00
parent 5bbffa60be
commit fef8fc92c5
@@ -265,6 +265,33 @@ describe('createRouter readonly disabled', () => {
});
});
describe('GET /locations/:id', () => {
it('happy path: gets location by id', async () => {
const location: Location = {
id: 'foo',
type: 'url',
target: 'example.com',
};
locationService.getLocation.mockResolvedValueOnce(location);
const response = await request(app)
.get('/locations/foo')
.set('authorization', 'Bearer someauthtoken');
expect(locationService.getLocation).toHaveBeenCalledTimes(1);
expect(locationService.getLocation).toHaveBeenCalledWith('foo', {
authorizationToken: 'someauthtoken',
});
expect(response.status).toEqual(200);
expect(response.body).toEqual({
id: 'foo',
target: 'example.com',
type: 'url',
});
});
});
describe('POST /locations', () => {
it('rejects malformed locations', async () => {
const spec = {
@@ -337,6 +364,23 @@ describe('createRouter readonly disabled', () => {
);
});
});
describe('DELETE /locations', () => {
it('deletes the location', async () => {
locationService.deleteLocation.mockResolvedValueOnce(undefined);
const response = await request(app)
.delete('/locations/foo')
.set('authorization', 'Bearer someauthtoken');
expect(locationService.deleteLocation).toHaveBeenCalledTimes(1);
expect(locationService.deleteLocation).toHaveBeenCalledWith('foo', {
authorizationToken: 'someauthtoken',
});
expect(response.status).toEqual(204);
});
});
});
describe('createRouter readonly enabled', () => {
@@ -430,6 +474,33 @@ describe('createRouter readonly enabled', () => {
});
});
describe('GET /locations/:id', () => {
it('happy path: gets location by id', async () => {
const location: Location = {
id: 'foo',
type: 'url',
target: 'example.com',
};
locationService.getLocation.mockResolvedValueOnce(location);
const response = await request(app)
.get('/locations/foo')
.set('authorization', 'Bearer someauthtoken');
expect(locationService.getLocation).toHaveBeenCalledTimes(1);
expect(locationService.getLocation).toHaveBeenCalledWith('foo', {
authorizationToken: 'someauthtoken',
});
expect(response.status).toEqual(200);
expect(response.body).toEqual({
id: 'foo',
target: 'example.com',
type: 'url',
});
});
});
describe('POST /locations', () => {
it('is not allowed', async () => {
const spec: LocationSpec = {
@@ -475,6 +546,17 @@ describe('createRouter readonly enabled', () => {
);
});
});
describe('DELETE /locations', () => {
it('is not allowed', async () => {
const response = await request(app)
.delete('/locations/foo')
.set('authorization', 'Bearer someauthtoken');
expect(locationService.deleteLocation).not.toHaveBeenCalled();
expect(response.status).toEqual(403);
});
});
});
describe('NextRouter permissioning', () => {