Skip to content
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
15 changes: 8 additions & 7 deletions openapi3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ paths:
value:
isValid: false
message: Record with name 'rec_X' not found
code: INVALID_RECORD_NAME
code: RECORD_NAME_NOT_FOUND
'500':
description: Internal server error
content:
Expand Down Expand Up @@ -312,7 +312,7 @@ paths:
value:
isValid: false
message: Record with name 'rec_X' not found
code: INVALID_RECORD_NAME
code: RECORD_NAME_NOT_FOUND
'500':
description: Internal server error
content:
Expand Down Expand Up @@ -399,7 +399,7 @@ paths:
value:
isValid: false
message: Cannot delete – record 'rec_X' not found
code: INVALID_RECORD_NAME
code: RECORD_NAME_NOT_FOUND
'500':
description: Internal server error
content:
Expand Down Expand Up @@ -487,7 +487,7 @@ paths:
value:
isValid: false
message: Record 'rec_name' already exists
code: INVALID_RECORD_NAME
code: RECORD_NAME_ALREADY_EXIST
'500':
description: Internal server error
content:
Expand Down Expand Up @@ -565,7 +565,7 @@ paths:
value:
isValid: false
message: Record 'rec_name' doesn't exists
code: INVALID_RECORD_NAME
code: RECORD_NAME_NOT_FOUND
'500':
description: Internal server error
content:
Expand Down Expand Up @@ -759,12 +759,13 @@ components:
type: string
enum:
- SUCCESS
- RECORD_NAME_ALREADY_EXIST
- MISSING_CREDENTIALS
- MISSING_COORDINATES
- INVALID_COORDINATES_OR_DISTANCE
- INVALID_CREDENTIALS
- INVALID_RECORD_NAME
- INVALID_RECORD_NAME_ANOTHER_SITE
- RECORD_NAME_NOT_FOUND
- RECORD_NAME_NOT_FOUND_ANOTHER_SITE
- INTERNAL_ERROR
- INVALID_START_POSITION
- INVALID_MAX_RECORDS
Expand Down
5 changes: 3 additions & 2 deletions src/openapi.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,13 @@ export type components = {
/** @enum {string} */
code:
| 'SUCCESS'
| 'RECORD_NAME_ALREADY_EXIST'
| 'MISSING_CREDENTIALS'
| 'MISSING_COORDINATES'
| 'INVALID_COORDINATES_OR_DISTANCE'
| 'INVALID_CREDENTIALS'
| 'INVALID_RECORD_NAME'
| 'INVALID_RECORD_NAME_ANOTHER_SITE'
| 'RECORD_NAME_NOT_FOUND'
| 'RECORD_NAME_NOT_FOUND_ANOTHER_SITE'
| 'INTERNAL_ERROR'
| 'INVALID_START_POSITION'
| 'INVALID_MAX_RECORDS';
Expand Down
9 changes: 5 additions & 4 deletions src/records/controllers/recordsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class RecordsController {
const record = await this.manager.getRecord(recordName);

if (!record) {
return res.status(httpStatus.NOT_FOUND).json({ isValid: false, message: `Record ${recordName} not found`, code: 'INVALID_RECORD_NAME' });
return res.status(httpStatus.NOT_FOUND).json({ isValid: false, message: `Record ${recordName} not found`, code: 'RECORD_NAME_NOT_FOUND' });
}

return res.status(httpStatus.OK).json(record);
Expand Down Expand Up @@ -165,7 +165,7 @@ export class RecordsController {

if (!deleted) {
this.requestsCounter.inc({ status: '404' });
return res.status(httpStatus.NOT_FOUND).json({ isValid: false, message: `Record ${recordName} not found`, code: 'INVALID_RECORD_NAME' });
return res.status(httpStatus.NOT_FOUND).json({ isValid: false, message: `Record ${recordName} not found`, code: 'RECORD_NAME_NOT_FOUND' });
}

this.requestsCounter.inc({ status: '204' });
Expand Down Expand Up @@ -224,9 +224,10 @@ export class RecordsController {
const code = result.code ?? 'UNKNOWN';
switch (code) {
case 'MISSING_CREDENTIALS':
case 'RECORD_NAME_ALREADY_EXIST':
return httpStatus.BAD_REQUEST;
case 'INVALID_RECORD_NAME':
case 'INVALID_RECORD_NAME_ANOTHER_SITE':
case 'RECORD_NAME_NOT_FOUND':
case 'RECORD_NAME_NOT_FOUND_ANOTHER_SITE':
return httpStatus.NOT_FOUND;
case 'INVALID_CREDENTIALS':
return httpStatus.UNAUTHORIZED;
Expand Down
8 changes: 4 additions & 4 deletions src/validations/models/validationsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class ValidationsManager {
const record = await this.extractableRepo.findOne({ where: { record_name: payload.recordName } });
if (record) {
this.logger.debug({ msg: 'record already exists for create', recordName: payload.recordName, logContext });
return { isValid: false, message: `Record '${payload.recordName}' already exists`, code: 'INVALID_RECORD_NAME' };
return { isValid: false, message: `Record '${payload.recordName}' already exists`, code: 'RECORD_NAME_ALREADY_EXIST' };
}

let existsAndPublishedInCatalog: boolean;
Expand All @@ -64,7 +64,7 @@ export class ValidationsManager {

if (!existsAndPublishedInCatalog) {
this.logger.debug({ msg: 'record does not exist in catalog', recordName: payload.recordName, logContext });
return { isValid: false, message: `Record '${payload.recordName}' is missing from the catalog`, code: 'INVALID_RECORD_NAME' };
return { isValid: false, message: `Record '${payload.recordName}' is missing from the catalog`, code: 'RECORD_NAME_NOT_FOUND' };
}

this.logger.debug({ msg: `multiSiteValidation ${payload.multiSiteValidation}`, logContext });
Expand Down Expand Up @@ -97,7 +97,7 @@ export class ValidationsManager {
const validOnOtherSites = results.every(Boolean);
if (!validOnOtherSites) {
this.logger.debug({ msg: 'record validation failed on another site', recordName: payload.recordName, logContext });
return { isValid: false, message: 'Record validation failed on another site', code: 'INVALID_RECORD_NAME_ANOTHER_SITE' };
return { isValid: false, message: 'Record validation failed on another site', code: 'RECORD_NAME_NOT_FOUND_ANOTHER_SITE' };
}
} catch (err) {
this.logger.warn({ msg: 'remote validation unavailable', recordName: payload.recordName, logContext, err });
Expand Down Expand Up @@ -125,7 +125,7 @@ export class ValidationsManager {
const record = await this.extractableRepo.findOne({ where: { record_name: payload.recordName } });
if (!record) {
this.logger.debug({ msg: 'record not found for delete', record_name: payload.recordName, logContext });
return { isValid: false, message: `Record '${payload.recordName}' not found`, code: 'INVALID_RECORD_NAME' };
return { isValid: false, message: `Record '${payload.recordName}' not found`, code: 'RECORD_NAME_NOT_FOUND' };
}

this.logger.debug({ msg: 'delete validation successful', recordName: payload.recordName, logContext });
Expand Down
22 changes: 11 additions & 11 deletions tests/integration/records/records.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ describe('records', function () {
});

expect(response).toSatisfyApiSpec();
expect(response.status).toBe(httpStatusCodes.NOT_FOUND);
expect(response.status).toBe(httpStatusCodes.BAD_REQUEST);
});

describe('Duplicate Creation', function () {
Expand All @@ -276,7 +276,7 @@ describe('records', function () {
});
});

it('should return 404 when createRecord throws "Record not found"', async () => {
it('should return 400 when createRecord throws "Record not found"', async () => {
const response = await requestSender.createRecord({
pathParams: { recordName: validCredentials.recordName },
requestBody: {
Expand All @@ -286,11 +286,11 @@ describe('records', function () {
},
});

expect(response.status).toBe(httpStatusCodes.NOT_FOUND);
expect(response.status).toBe(httpStatusCodes.BAD_REQUEST);
expect(response.body).toEqual({
isValid: false,
message: `Record 'rec_name' already exists`,
code: 'INVALID_RECORD_NAME',
code: 'RECORD_NAME_ALREADY_EXIST',
});
});
});
Expand Down Expand Up @@ -521,7 +521,7 @@ describe('records', function () {
expect(response.body).toEqual({
isValid: false,
message: `Record ${invalidCredentials.recordName} not found`,
code: 'INVALID_RECORD_NAME',
code: 'RECORD_NAME_NOT_FOUND',
});
});

Expand All @@ -534,11 +534,11 @@ describe('records', function () {
expect(response.status).toBe(httpStatusCodes.NOT_FOUND);
});

it('should return 404 when validateCreate returns INVALID_RECORD_NAME', async () => {
it('should return 404 when validateCreate returns RECORD_NAME_NOT_FOUND', async () => {
jest.spyOn(ValidationsManager.prototype, 'validateCreate').mockResolvedValueOnce({
isValid: false,
message: 'Record does not exist',
code: 'INVALID_RECORD_NAME',
code: 'RECORD_NAME_NOT_FOUND',
});

const response = await requestSender.validateCreate({
Expand All @@ -553,17 +553,17 @@ describe('records', function () {
expect(response.body).toEqual({
isValid: false,
message: 'Record does not exist',
code: 'INVALID_RECORD_NAME',
code: 'RECORD_NAME_NOT_FOUND',
});

jest.restoreAllMocks();
});

it('should return 404 when validateDelete returns INVALID_RECORD_NAME', async () => {
it('should return 404 when validateDelete returns RECORD_NAME_NOT_FOUND', async () => {
jest.spyOn(ValidationsManager.prototype, 'validateDelete').mockResolvedValueOnce({
isValid: false,
message: 'Record does not exist',
code: 'INVALID_RECORD_NAME',
code: 'RECORD_NAME_NOT_FOUND',
});

const response = await requestSender.validateDelete({
Expand All @@ -578,7 +578,7 @@ describe('records', function () {
expect(response.body).toEqual({
isValid: false,
message: 'Record does not exist',
code: 'INVALID_RECORD_NAME',
code: 'RECORD_NAME_NOT_FOUND',
});

jest.restoreAllMocks();
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/records/models/recordsModel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ describe('RecordsManager & ValidationsManager', () => {
code: 'INTERNAL_ERROR',
});
});
it('should return INVALID_RECORD_NAME if catalog does not contain record', async () => {
it('should return RECORD_NAME_NOT_FOUND if catalog does not contain record', async () => {
(mockCatalogCall as unknown as CatalogCall).findPublishedRecord = jest.fn().mockResolvedValueOnce(false);

const result = await validationsManager.validateCreate({
Expand All @@ -284,7 +284,7 @@ describe('RecordsManager & ValidationsManager', () => {
expect(result).toEqual({
isValid: false,
message: "Record 'missingRecord' is missing from the catalog",
code: 'INVALID_RECORD_NAME',
code: 'RECORD_NAME_NOT_FOUND',
});
});
});
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/users/models/usersModel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ describe('ValidationsManager - User & Record Validation', () => {

expect(result.isValid).toBe(false);
expect(result.message).toBe("Record 'existingRecord' already exists");
expect(result.code).toBe('INVALID_RECORD_NAME');
expect(result.code).toBe('RECORD_NAME_ALREADY_EXIST');
});

describe('Remote Validation', () => {
Expand Down Expand Up @@ -167,7 +167,7 @@ describe('ValidationsManager - User & Record Validation', () => {
const routes = [{ url: 'http://site1.com' }, { url: 'http://site2.com' }];
mockedAxios.post
.mockResolvedValueOnce({ data: { isValid: true, code: 'SUCCESS', message: 'Valid' } })
.mockResolvedValueOnce({ data: { isValid: false, code: 'INVALID_RECORD_NAME', message: 'Invalid' } });
.mockResolvedValueOnce({ data: { isValid: false, code: 'RECORD_NAME_NOT_FOUND', message: 'Invalid' } });

validationsManager = createValidationsManager({
get: (key: string) => {
Expand All @@ -183,7 +183,7 @@ describe('ValidationsManager - User & Record Validation', () => {

expect(result.isValid).toBe(false);
expect(result.message).toBe('Record validation failed on another site');
expect(result.code).toBe('INVALID_RECORD_NAME_ANOTHER_SITE');
expect(result.code).toBe('RECORD_NAME_NOT_FOUND_ANOTHER_SITE');
});

it('should return false for remote site when fetch fails', async () => {
Expand All @@ -206,7 +206,7 @@ describe('ValidationsManager - User & Record Validation', () => {

expect(result.isValid).toBe(false);
expect(result.message).toBe('Record validation failed on another site');
expect(result.code).toBe('INVALID_RECORD_NAME_ANOTHER_SITE');
expect(result.code).toBe('RECORD_NAME_NOT_FOUND_ANOTHER_SITE');
});

it('should handle remote validation config retrieval failure (routes load failure at construction)', async () => {
Expand Down Expand Up @@ -247,7 +247,7 @@ describe('ValidationsManager - User & Record Validation', () => {

expect(result.isValid).toBe(false);
expect(result.message).toBe('Record validation failed on another site');
expect(result.code).toBe('INVALID_RECORD_NAME_ANOTHER_SITE');
expect(result.code).toBe('RECORD_NAME_NOT_FOUND_ANOTHER_SITE');
});
});
});
Expand All @@ -272,7 +272,7 @@ describe('ValidationsManager - User & Record Validation', () => {

expect(result.isValid).toBe(false);
expect(result.message).toBe("Record 'nonExistingRecord' not found");
expect(result.code).toBe('INVALID_RECORD_NAME');
expect(result.code).toBe('RECORD_NAME_NOT_FOUND');
});
});
});
Loading