Skip to content

Commit

Permalink
#585: added tests for health activities
Browse files Browse the repository at this point in the history
  • Loading branch information
basmasking committed Dec 31, 2024
1 parent 7be4cad commit b2aef61
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
32 changes: 32 additions & 0 deletions packages/http/test/HttpRemote.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,38 @@ describe('HttpRemote', () =>
});
});

describe('isHealthy', () =>
{
it('should return true when the server is healthy', async () =>
{
const remote = new HttpRemote(VALUES.REMOTE.IS_HEALTHY, dummyFetch);
const healthy = await remote.isHealthy();

expect(healthy).toBe(true);
});

it('should return false when the server is unhealthy', async () =>
{
const remote = new HttpRemote(VALUES.REMOTE.IS_UNHEALTHY, dummyFetch);
const healthy = await remote.isHealthy();

expect(healthy).toBe(false);
});
});

describe('getHealth', () =>
{
it('should return health status per health check', async () =>
{
const remote = new HttpRemote(VALUES.REMOTE.DUMMY, dummyFetch);
const health = await remote.getHealth();

expect(health).toBeDefined();
expect(health.get(VALUES.OUTPUT.GET_HEALTH.database.key)).toBe(VALUES.OUTPUT.GET_HEALTH.database.value);
expect(health.get(VALUES.OUTPUT.GET_HEALTH.filestore.key)).toBe(VALUES.OUTPUT.GET_HEALTH.filestore.value);
});
});

describe('addWorker', () =>
{
it('should add a worker with a valid response', async () =>
Expand Down
3 changes: 3 additions & 0 deletions packages/http/test/fixtures/httpResponses.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ const HTTP_RESPONSES = new Map();

HTTP_RESPONSES.set(VALUES.URI.FILE_WITH_CONTENT_TYPE, VALUES.RESPONSE.FILE_WITH_CONTENT_TYPE);
HTTP_RESPONSES.set(VALUES.URI.FILE_WITH_DEFAULT_CONTENT_TYPE, VALUES.RESPONSE.FILE_WITH_DEFAULT_CONTENT_TYPE);
HTTP_RESPONSES.set(VALUES.URI.IS_HEALTHY, VALUES.RESPONSE.IS_HEALTHY);
HTTP_RESPONSES.set(VALUES.URI.IS_UNHEALTHY, VALUES.RESPONSE.IS_UNHEALTHY);
HTTP_RESPONSES.set(VALUES.URI.GET_HEALTH, VALUES.RESPONSE.GET_HEALTH);
HTTP_RESPONSES.set(VALUES.URI.ADD_WORKER_VALID, VALUES.RESPONSE.ADD_WORKER_VALID);
HTTP_RESPONSES.set(VALUES.URI.ADD_WORKER_INVALID_ID, VALUES.RESPONSE.ADD_WORKER_INVALID_ID);
HTTP_RESPONSES.set(VALUES.URI.ADD_WORKER_INVALID_REQUEST, VALUES.RESPONSE.ADD_WORKER_INVALID_REQUEST);
Expand Down
32 changes: 32 additions & 0 deletions packages/http/test/fixtures/values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { Request, RunModes, Version } from '@jitar/execution';
const VALUES = {
REMOTE: {
DUMMY: 'http://dummy.remote',
IS_HEALTHY: 'http://is.healthy',
IS_UNHEALTHY: 'http://is.unhealthy',
ADD_WORKER_VALID: 'http://valid.add.worker.remote',
ADD_WORKER_INVALID_ID: 'http://invalid.add.worker.id.remote',
ADD_WORKER_INVALID_REQUEST: 'http://invalid.add.worker.request.remote'
Expand All @@ -12,6 +14,9 @@ const VALUES = {
URI: {
FILE_WITH_CONTENT_TYPE: 'http://dummy.remote/index.html',
FILE_WITH_DEFAULT_CONTENT_TYPE: 'http://dummy.remote/index.bin',
IS_HEALTHY: 'http://is.healthy/health/status',
IS_UNHEALTHY: 'http://is.unhealthy/health/status',
GET_HEALTH: 'http://dummy.remote/health',
ADD_WORKER_VALID: 'http://valid.add.worker.remote/workers',
ADD_WORKER_INVALID_ID: 'http://invalid.add.worker.id.remote/workers',
ADD_WORKER_INVALID_REQUEST: 'http://invalid.add.worker.request.remote/workers',
Expand Down Expand Up @@ -50,6 +55,21 @@ const VALUES = {
{ status: 200 }
),

IS_HEALTHY: new Response(
'true',
{ status: 200, headers: { 'Content-Type': 'text/plain' } }
),

IS_UNHEALTHY: new Response(
'false',
{ status: 200, headers: { 'Content-Type': 'text/plain' } }
),

GET_HEALTH: new Response(
'{ "database": true, "filestore": false }',
{ status: 200, headers: { 'Content-Type': 'application/json' } }
),

ADD_WORKER_VALID: new Response(
'{ "id": "1" }',
{ status: 200, headers: { 'Content-Type': 'application/json' } }
Expand Down Expand Up @@ -85,6 +105,18 @@ const VALUES = {
location: 'index.bin',
type: 'application/octet-stream'
},
IS_HEALTHY: true,
IS_UNHEALTHY: false,
GET_HEALTH: {
database: {
key: 'database',
value: true
},
filestore: {
key: 'filestore',
value: false
}
},
ADD_WORKER_VALID: '1',
RUN_VALID: {
status: 200,
Expand Down

0 comments on commit b2aef61

Please sign in to comment.