mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
chore: add common/api/types/api tests
This commit is contained in:
15
Common/Tests/Dictionary.test.ts
Normal file
15
Common/Tests/Dictionary.test.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import Dictionary from '../Types/Dictionary';
|
||||
describe('Dictionary', () => {
|
||||
test('should allow basic types compile', () => {
|
||||
const user: Dictionary<string> = {
|
||||
user: 'test',
|
||||
};
|
||||
expect(user).toBeTruthy();
|
||||
});
|
||||
test('should compile', () => {
|
||||
const user: Dictionary<{ [x: string]: string }> = {
|
||||
user: { use: 'welcome' },
|
||||
};
|
||||
expect(user).toBeTruthy();
|
||||
});
|
||||
});
|
||||
12
Common/Tests/ErrorResponse.test.ts
Normal file
12
Common/Tests/ErrorResponse.test.ts
Normal file
@@ -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',
|
||||
});
|
||||
});
|
||||
});
|
||||
16
Common/Tests/HTTPMethod.test.ts
Normal file
16
Common/Tests/HTTPMethod.test.ts
Normal file
@@ -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');
|
||||
});
|
||||
});
|
||||
10
Common/Tests/Headers.test.ts
Normal file
10
Common/Tests/Headers.test.ts
Normal file
@@ -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();
|
||||
});
|
||||
});
|
||||
8
Common/Tests/Hostname.test.ts
Normal file
8
Common/Tests/Hostname.test.ts
Normal file
@@ -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');
|
||||
});
|
||||
});
|
||||
16
Common/Tests/Protocal.test.ts
Normal file
16
Common/Tests/Protocal.test.ts
Normal file
@@ -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://');
|
||||
});
|
||||
});
|
||||
12
Common/Tests/Response.test.ts
Normal file
12
Common/Tests/Response.test.ts
Normal file
@@ -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' }]);
|
||||
});
|
||||
});
|
||||
12
Common/Tests/ResponseType.test.ts
Normal file
12
Common/Tests/ResponseType.test.ts
Normal file
@@ -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');
|
||||
});
|
||||
});
|
||||
11
Common/Tests/Route.test.ts
Normal file
11
Common/Tests/Route.test.ts
Normal file
@@ -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');
|
||||
});
|
||||
});
|
||||
42
Common/Tests/URL.test.ts
Normal file
42
Common/Tests/URL.test.ts
Normal file
@@ -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');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user