feat: completed methods for endpoint factory

This commit is contained in:
StevanFreeborn
2023-01-26 23:07:59 -06:00
parent af806e71ad
commit 4258793544
2 changed files with 161 additions and 6 deletions
+84
View File
@@ -154,4 +154,88 @@ export class EndpointFactory {
): string {
return `${baseUrl}/Records/appId/${appId}`;
}
/**
* @param {string} baseUrl - The base url that will be used to create the get record by id endpoint.
* @param {number} appId - The id of the app.
* @param {number} recordId - The id of the record.
* @returns {string} - The get record by id endpoint.
*/
public static getRecordByIdEndpoint(
baseUrl: string,
appId: number,
recordId: number
): string {
return `${baseUrl}/Records/appId/${appId}/recordId/${recordId}`;
}
/**
* @param {string} baseUrl - The base url that will be used to create the delete record by id endpoint.
* @param {number} appId - The id of the app.
* @param {number} recordId - The id of the record.
* @returns {string} - The delete record by id endpoint.
*/
public static getDeleteRecordByIdEndpoint(
baseUrl: string,
appId: number,
recordId: number
): string {
return `${baseUrl}/Records/appId/${appId}/recordId/${recordId}`;
}
/**
* @param {string} baseUrl - The base url that will be used to create the get records by ids endpoint.
* @returns {string} - The get records by ids endpoint.
*/
public static getRecordsByIdsEndpoint(baseUrl: string): string {
return `${baseUrl}/Records/batch-get`;
}
/**
* @param {string} baseUrl - The base url that will be used to create the query records endpoint.
* @returns {string} - The query records endpoint.
*/
public static getQueryRecordsEndpoint(baseUrl: string): string {
return `${baseUrl}/Records/query`;
}
/**
* @param {string} baseUrl - The base url that will be used to create the add or update record endpoint.
* @returns {string} - The add or update record endpoint.
*/
public static getAddOrUpdateRecordEndpoint(baseUrl: string): string {
return `${baseUrl}/Records`;
}
/**
* @param {string} baseUrl - The base url that will be used to create the delete records by ids endpoint.
* @returns {string} - The delete records by ids endpoint.
*/
public static getDeleteRecordsByIdsEndpoint(baseUrl: string): string {
return `${baseUrl}/Records/batch-delete`;
}
/**
* @param {string} baseUrl - The base url that will be used to create the get report by id endpoint.
* @param {number} reportId - The id of the report.
* @returns {string} - The get report by id endpoint.
*/
public static getReportByIdEndpoint(
baseUrl: string,
reportId: number
): string {
return `${baseUrl}/Reports/id/${reportId}`;
}
/**
* @param {string} baseUrl - The base url that will be used to create the get reports by app id endpoint.
* @param {number} appId - The id of the app.
* @returns {string} - The get reports by app id endpoint.
*/
public static getReportsByAppIdEndpoint(
baseUrl: string,
appId: number
): string {
return `${baseUrl}/Reports/appId/${appId}`;
}
}
+77 -6
View File
@@ -62,15 +62,24 @@ describe('EndpointFactory', function () {
describe('getDeleteFileByIdEndpoint', function () {
it('should return the correct delete file endpoint', function () {
const result = EndpointFactory.getDeleteFileByIdEndpoint(baseUrl, 1, 2, 3);
expect(result).to.equal(`${baseUrl}/Files/recordId/1/fieldId/2/fileId/3/file`);
const result = EndpointFactory.getDeleteFileByIdEndpoint(
baseUrl,
1,
2,
3
);
expect(result).to.equal(
`${baseUrl}/Files/recordId/1/fieldId/2/fileId/3/file`
);
});
});
describe('getFileByIdEndpoint', function () {
it('should return the correct get file endpoint', function () {
const result = EndpointFactory.getFileByIdEndpoint(baseUrl, 1, 2, 3);
expect(result).to.equal(`${baseUrl}/Files/recordId/1/fieldId/2/fileId/3/file`);
expect(result).to.equal(
`${baseUrl}/Files/recordId/1/fieldId/2/fileId/3/file`
);
});
});
@@ -90,15 +99,77 @@ describe('EndpointFactory', function () {
describe('getDeleteListItemEndpoint', function () {
it('should return the correct delete list item endpoint', function () {
const result = EndpointFactory.getDeleteListItemEndpoint(baseUrl, 1, '612ac495-8aad-44fd-b57d-1ae798dcf1a5');
expect(result).to.equal(`${baseUrl}/Lists/id/1/itemId/612ac495-8aad-44fd-b57d-1ae798dcf1a5`);
const result = EndpointFactory.getDeleteListItemEndpoint(
baseUrl,
1,
'612ac495-8aad-44fd-b57d-1ae798dcf1a5'
);
expect(result).to.equal(
`${baseUrl}/Lists/id/1/itemId/612ac495-8aad-44fd-b57d-1ae798dcf1a5`
);
});
});
describe('getRecordsByAppIdEndpoint', function () {
describe('getRecordsByAppIdEndpoint', function () {
it('should return the correct records by app id endpoint', function () {
const result = EndpointFactory.getRecordsByAppIdEndpoint(baseUrl, 1);
expect(result).to.equal(`${baseUrl}/Records/appId/1`);
});
});
describe('getRecordByIdEndpoint', function () {
it('should return the correct record by id endpoint', function () {
const result = EndpointFactory.getRecordByIdEndpoint(baseUrl, 1, 2);
expect(result).to.equal(`${baseUrl}/Records/appId/1/recordId/2`);
});
});
describe('getDeleteRecordByIdEndpoint', function () {
it('should return the correct delete record by id endpoint', function () {
const result = EndpointFactory.getDeleteRecordByIdEndpoint(baseUrl, 1, 2);
expect(result).to.equal(`${baseUrl}/Records/appId/1/recordId/2`);
});
});
describe('getRecordsByIdsEndpoint', function () {
it('should return the correct records by ids endpoint', function () {
const result = EndpointFactory.getRecordsByIdsEndpoint(baseUrl);
expect(result).to.equal(`${baseUrl}/Records/batch-get`);
});
});
describe('getQueryRecordsEndpoint', function(){
it('should return the correct query records endpoint', function(){
const result = EndpointFactory.getQueryRecordsEndpoint(baseUrl);
expect(result).to.equal(`${baseUrl}/Records/query`);
});
});
describe('getAddOrUpdateRecordEndpoint', function () {
it('should return the correct add or update record endpoint', function () {
const result = EndpointFactory.getAddOrUpdateRecordEndpoint(baseUrl);
expect(result).to.equal(`${baseUrl}/Records`);
});
});
describe('getDeleteRecordsByIdsEndpoint', function () {
it('should return the correct delete records by ids endpoint', function () {
const result = EndpointFactory.getDeleteRecordsByIdsEndpoint(baseUrl);
expect(result).to.equal(`${baseUrl}/Records/batch-delete`);
});
});
describe('getReportByIdEndpoint', function () {
it('should return the correct report by id endpoint', function () {
const result = EndpointFactory.getReportByIdEndpoint(baseUrl, 1);
expect(result).to.equal(`${baseUrl}/Reports/id/1`);
});
});
describe('getReportsByAppIdEndpoint', function () {
it('should return the correct reports by app id endpoint', function () {
const result = EndpointFactory.getReportsByAppIdEndpoint(baseUrl, 1);
expect(result).to.equal(`${baseUrl}/Reports/appId/1`);
});
});
});