feat: begin adding endpoint factory methods and tests
This commit is contained in:
+3
-2
@@ -5,8 +5,9 @@
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"scripts": {
|
||||
"build": "npm test && tsc",
|
||||
"test": "mocha -r ts-node/register ./tests/**/*.spec.ts"
|
||||
"build": "npm tests && tsc",
|
||||
"tests": "mocha -r ts-node/register ./tests/**/*.spec.ts",
|
||||
"test": "mocha -r ts-node/register"
|
||||
},
|
||||
"author": "Stevan Freeborn",
|
||||
"license": "MIT",
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
export class EndpointFactory {
|
||||
public static getPingEndpoint(baseUrl: string): string {
|
||||
return `${baseUrl}/Ping`;
|
||||
}
|
||||
|
||||
public static getAppsEndpoint(baseUrl: string): string {
|
||||
return `${baseUrl}/Apps`;
|
||||
}
|
||||
|
||||
public static getAppByIdEndpoint(baseUrl: string, id: number): string {
|
||||
return `${baseUrl}/Apps/id/${id}`;
|
||||
}
|
||||
|
||||
public static getAppsByIdsEndpoint(baseUrl: string): string {
|
||||
return `${baseUrl}/Apps/batch-get`;
|
||||
}
|
||||
|
||||
public static getFieldByIdEndpoint(baseUrl: string, id: number): string {
|
||||
return `${baseUrl}/Fields/id/${id}`;
|
||||
}
|
||||
|
||||
public static getFieldsByIdsEndpoint(baseUrl: string): string {
|
||||
return `${baseUrl}/Fields/batch-get`;
|
||||
}
|
||||
|
||||
public static getFieldsByAppIdEndpoint(baseUrl: string, id: number): string {
|
||||
return `${baseUrl}/Fields/appId/${id}`;
|
||||
}
|
||||
|
||||
public static getFileInfoByIdEndpoint(baseUrl: string, recordId: number, fieldId: number, fileId: number): string {
|
||||
return `${baseUrl}/Files/recordId/${recordId}/fieldId/${fieldId}/fileId/${fileId}`;
|
||||
}
|
||||
|
||||
public static getDeleteFileByIdEndpoint(baseUrl: string, recordId: number, fieldId: number, fileId: number): string {
|
||||
return `${baseUrl}/Files/recordId/${recordId}/fieldId/${fieldId}/fileId/${fileId}/file`;
|
||||
}
|
||||
|
||||
public static getFileByIdEndpoint(baseUrl: string, recordId: number, fieldId: number, fileId: number): string {
|
||||
return `${baseUrl}/Files/recordId/${recordId}/fieldId/${fieldId}/fileId/${fileId}/file`;
|
||||
}
|
||||
|
||||
public static getSaveFileEndpoint(baseUrl: string): string {
|
||||
return `${baseUrl}/Files`;
|
||||
}
|
||||
|
||||
public static getAddOrUpdateListItemEndpoint(baseUrl: string, listId: number): string {
|
||||
return `${baseUrl}/Lists/id/${listId}/items`;
|
||||
}
|
||||
|
||||
public static getDeleteListItemEndpoint(baseUrl: string, listId: number, itemId: string): string {
|
||||
return `${baseUrl}/Lists/id/${listId}/itemId/${itemId}`;
|
||||
}
|
||||
|
||||
public static getRecordsByAppIdEndpoint(baseUrl: string, appId: number): string {
|
||||
return `${baseUrl}/Records/appId/${appId}`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
import { EndpointFactory } from '../src/Models/EndpointFactory';
|
||||
import { expect } from 'chai';
|
||||
|
||||
describe('EndpointFactory', function () {
|
||||
const baseUrl = 'https://api.onspring.com';
|
||||
|
||||
describe('getPingEndpoint', function () {
|
||||
it('should return the correct ping endpoint', function () {
|
||||
const result = EndpointFactory.getPingEndpoint(baseUrl);
|
||||
expect(result).to.equal(`${baseUrl}/Ping`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getAppsEndpoint', function () {
|
||||
it('should return the correct apps endpoint', function () {
|
||||
const result = EndpointFactory.getAppsEndpoint(baseUrl);
|
||||
expect(result).to.equal(`${baseUrl}/Apps`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getAppByIdEndpoint', function () {
|
||||
it('should return the correct app by id endpoint', function () {
|
||||
const result = EndpointFactory.getAppByIdEndpoint(baseUrl, 1);
|
||||
expect(result).to.equal(`${baseUrl}/Apps/id/1`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getAppsByIdsEndpoint', function () {
|
||||
it('should return the correct apps by ids endpoint', function () {
|
||||
const result = EndpointFactory.getAppsByIdsEndpoint(baseUrl);
|
||||
expect(result).to.equal(`${baseUrl}/Apps/batch-get`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getFieldByIdEndpoint', function () {
|
||||
it('should return the correct field by id endpoint', function () {
|
||||
const result = EndpointFactory.getFieldByIdEndpoint(baseUrl, 1);
|
||||
expect(result).to.equal(`${baseUrl}/Fields/id/1`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getFieldsByIdsEndpoint', function () {
|
||||
it('should return the correct fields by ids endpoint', function () {
|
||||
const result = EndpointFactory.getFieldsByIdsEndpoint(baseUrl);
|
||||
expect(result).to.equal(`${baseUrl}/Fields/batch-get`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getFieldsByAppIdEndpoint', function () {
|
||||
it('should return the correct fields by app id endpoint', function () {
|
||||
const result = EndpointFactory.getFieldsByAppIdEndpoint(baseUrl, 1);
|
||||
expect(result).to.equal(`${baseUrl}/Fields/appId/1`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getFileInfoByIdEndpoint', function () {
|
||||
it('should return the correct get file info endpoint', function () {
|
||||
const result = EndpointFactory.getFileInfoByIdEndpoint(baseUrl, 1, 2, 3);
|
||||
expect(result).to.equal(`${baseUrl}/Files/recordId/1/fieldId/2/fileId/3`);
|
||||
});
|
||||
});
|
||||
|
||||
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`);
|
||||
});
|
||||
});
|
||||
|
||||
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`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getSaveFileEndpoint', function () {
|
||||
it('should return the correct save file endpoint', function () {
|
||||
const result = EndpointFactory.getSaveFileEndpoint(baseUrl);
|
||||
expect(result).to.equal(`${baseUrl}/Files`);
|
||||
});
|
||||
});
|
||||
|
||||
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`);
|
||||
});
|
||||
});
|
||||
|
||||
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`);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user