diff --git a/Common/Tests/Dictionary.test.ts b/Common/Tests/Dictionary.test.ts new file mode 100644 index 0000000000..330d275505 --- /dev/null +++ b/Common/Tests/Dictionary.test.ts @@ -0,0 +1,15 @@ +import Dictionary from '../Types/Dictionary'; +describe('Dictionary', () => { + test('should allow basic types compile', () => { + const user: Dictionary = { + user: 'test', + }; + expect(user).toBeTruthy(); + }); + test('should compile', () => { + const user: Dictionary<{ [x: string]: string }> = { + user: { use: 'welcome' }, + }; + expect(user).toBeTruthy(); + }); +}); diff --git a/Common/Tests/ErrorResponse.test.ts b/Common/Tests/ErrorResponse.test.ts new file mode 100644 index 0000000000..a3fc79047b --- /dev/null +++ b/Common/Tests/ErrorResponse.test.ts @@ -0,0 +1,12 @@ +import ErrorResponse from '../Types/API/ErrorResponse'; +describe('ErrorResponse', () => { + test('should return a valid error response object', () => { + const errorResponseObject: ErrorResponse = new ErrorResponse(500, { + error: 'Internal Server Error', + }); + expect(errorResponseObject.statusCode).toBe(500); + expect(errorResponseObject.data).toEqual({ + error: 'Internal Server Error', + }); + }); +}); diff --git a/Common/Tests/HTTPMethod.test.ts b/Common/Tests/HTTPMethod.test.ts new file mode 100644 index 0000000000..b0af2a1535 --- /dev/null +++ b/Common/Tests/HTTPMethod.test.ts @@ -0,0 +1,16 @@ +import HTTPMethod from '../Types/API/HTTPMethod'; + +describe('HTTPMethod', () => { + test('HTTPMethod.GET should be GET', () => { + expect(HTTPMethod.GET).toBe('GET'); + }); + test('HTTPMethod.POST should be POST', () => { + expect(HTTPMethod.POST).toBe('POST'); + }); + test('HTTPMethod.PUT should be PUT', () => { + expect(HTTPMethod.PUT).toBe('PUT'); + }); + test('HTTPMethod.DELETE should be DELETE', () => { + expect(HTTPMethod.DELETE).toBe('DELETE'); + }); +}); diff --git a/Common/Tests/Headers.test.ts b/Common/Tests/Headers.test.ts new file mode 100644 index 0000000000..1275d90790 --- /dev/null +++ b/Common/Tests/Headers.test.ts @@ -0,0 +1,10 @@ +import Headers from '../Types/API/Headers'; +describe('Headers', () => { + test('should compile', () => { + const headers: Headers = { + accept: 'application/json', + 'x-api-number': '2', + }; + expect(headers).toBeTruthy(); + }); +}); diff --git a/Common/Tests/Hostname.test.ts b/Common/Tests/Hostname.test.ts new file mode 100644 index 0000000000..5d6cf21757 --- /dev/null +++ b/Common/Tests/Hostname.test.ts @@ -0,0 +1,8 @@ +import Hostname from '../Types/API/Hostname'; +describe('Hostname', () => { + test('new Hostname(hostname) should return a valid object', () => { + const hostnameObject: Hostname = new Hostname('localhost:5000'); + expect(hostnameObject.hostname).toBeTruthy(); + expect(hostnameObject.hostname).toBe('localhost:5000'); + }); +}); diff --git a/Common/Tests/Protocal.test.ts b/Common/Tests/Protocal.test.ts new file mode 100644 index 0000000000..c03085d3d5 --- /dev/null +++ b/Common/Tests/Protocal.test.ts @@ -0,0 +1,16 @@ +import Protocol from '../Types/API/Protocol'; + +describe('Protocol', () => { + test('Protocol.HTTPS should be https://', () => { + expect(Protocol.HTTPS).toBe('https://'); + }); + test('Protocol.HTTP should be https://', () => { + expect(Protocol.HTTP).toBe('http://'); + }); + test('Protocol.WS should be ws://', () => { + expect(Protocol.WS).toBe('ws://'); + }); + test('Protocol.MONGO_DB should be mongodb://', () => { + expect(Protocol.MONGO_DB).toBe('mongodb://'); + }); +}); diff --git a/Common/Tests/Response.test.ts b/Common/Tests/Response.test.ts new file mode 100644 index 0000000000..5f72102026 --- /dev/null +++ b/Common/Tests/Response.test.ts @@ -0,0 +1,12 @@ +import Response from '../Types/API/Response'; +describe('Response()', () => { + test('should return a valid response object', () => { + let responseObject: Response; + responseObject = new Response(200, { welcome: 'here' }); + expect(responseObject.statusCode).toBe(200); + expect(responseObject.data).toEqual({ welcome: 'here' }); + responseObject = new Response(200, [{ welcome: 'here' }]); + expect(responseObject.statusCode).toBe(200); + expect(responseObject.data).toEqual([{ welcome: 'here' }]); + }); +}); diff --git a/Common/Tests/ResponseType.test.ts b/Common/Tests/ResponseType.test.ts new file mode 100644 index 0000000000..e9c7993adf --- /dev/null +++ b/Common/Tests/ResponseType.test.ts @@ -0,0 +1,12 @@ +import ResponseType from '../Types/API/ResponseType'; +describe('ResponseType', () => { + test('ResponsetType.CSV to be csv', () => { + expect(ResponseType.CSV).toBe('csv'); + }); + test('ResponseType.HTML to be json', () => { + expect(ResponseType.HTML).toBe('html'); + }); + test('ResponseType.HTML to be', () => { + expect(ResponseType.JSON).toBe('json'); + }); +}); diff --git a/Common/Tests/Route.test.ts b/Common/Tests/Route.test.ts new file mode 100644 index 0000000000..ad038953c3 --- /dev/null +++ b/Common/Tests/Route.test.ts @@ -0,0 +1,11 @@ +import Route from '../Types/API/Route'; +describe('Route', () => { + test('new Route should return a create object', () => { + const route: Route = new Route('/api/test'); + expect(route.route).toBe('/api/test'); + }); + test('Route.toString() should return valid string', () => { + const route: Route = new Route('/api/test'); + expect(route.toString()).toBe('/api/test'); + }); +}); diff --git a/Common/Tests/URL.test.ts b/Common/Tests/URL.test.ts new file mode 100644 index 0000000000..5fa0ca2e5d --- /dev/null +++ b/Common/Tests/URL.test.ts @@ -0,0 +1,42 @@ +import Hostname from '../Types/API/Hostname'; +import Protocol from '../Types/API/Protocol'; +import Route from '../Types/API/Route'; +import URL from '../Types/API/URL'; + +describe('URL', () => { + test('new URL() should return a valid object', () => { + const url: URL = new URL( + Protocol.HTTPS, + new Hostname('localhost:5000'), + new Route('/api/test') + ); + expect(url.hostname).toBeInstanceOf(Hostname); + expect(url.protocol).toBe('https://'); + expect(url.route).toBeInstanceOf(Route); + expect(url.isHttps()).toBe(true); + expect(url.toString).toBeTruthy(); + }); + test('URL.fromString should create URL object', () => { + let url: URL = URL.fromString('https://localhost:5000/api/test'); + expect(url).toBeInstanceOf(URL); + expect(url.protocol).toBe('https://'); + url = URL.fromString('mongodb://localhost:27017/test'); + expect(url).toBeInstanceOf(URL); + expect(url.protocol).toBe('mongodb://'); + url = URL.fromString('ws://localhost:5000/api/test'); + expect(url).toBeInstanceOf(URL); + expect(url.protocol).toBe('ws://'); + url = URL.fromString('wss://localhost:5000/api/test'); + expect(url).toBeInstanceOf(URL); + expect(url.protocol).toBe('wss://'); + }); + + test('URL.toString should return a valid URL', () => { + const url: URL = new URL( + Protocol.HTTPS, + new Hostname('localhost:5000'), + new Route('/api/test') + ); + expect(url.toString()).toBe('https://localhost:5000/api/test'); + }); +});