Skip to content

Commit

Permalink
DSP-817 Health Endpoint: integrate test data (#251)
Browse files Browse the repository at this point in the history
* tests (health endpoint): integrate test data

* tests (health endpoint): integrate test data

* tests (health endpoint): integrate test data

* tests (health endpoint): simplify header response handling

* docs: Update README

Co-authored-by: André Kilchenmann <[email protected]>
  • Loading branch information
tobiasschweizer and kilchenmann authored Oct 28, 2020
1 parent b62ab74 commit f9914db
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 14 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ generate-test-data: ## prepare test data from Knora-API

.PHONY: delete-test-data
delete-test-data: ## delete static test data before integration
rm -rf test/data/api/system/health/*
rm -rf test/data/api/admin/groups/*
rm -rf test/data/api/admin/lists/*
rm -rf test/data/api/admin/permissions/*
Expand All @@ -61,6 +62,7 @@ delete-test-data: ## delete static test data before integration

.PHONY: integrate-test-data
integrate-test-data: ## integrates generated test data
npm run integrate-system-test-data $(CURRENT_DIR)/.tmp/typescript/test-data
npm run integrate-admin-test-data $(CURRENT_DIR)/.tmp/typescript/test-data
npm run integrate-v2-test-data $(CURRENT_DIR)/.tmp/typescript/test-data
npm run expand-jsonld-test-data
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ If you need a local version of this lib that contains the mocks, do the followin
DSP-JS is compatible with a specified release of DSP-API.
To update the target release of DSP-API, the following steps have to be carried out:

1. Update DSP-API version in `vars.mk`, e.g., change `v13.0.0-rc.16` to `v13.0.0-rc.17`.
1. Update DSP-API version in
- `vars.mk`, e.g., change `v13.0.0-rc.16` to `v13.0.0-rc.17`.
- `src/api/system/health/health-endpoint.spec.ts`
1. Delete local test data with `make delete-test-data`
1. Generate test data using the target DSP-API release,
- Variant 1: See <https://docs.knora.org> -> Internals -> Development -> Generating Client Test Data
Expand All @@ -144,7 +146,6 @@ To update the target release of DSP-API, the following steps have to be carried
- change to directory `test-framework`
- add the locally build library using `npm run yalc-add` and run `npm install`
- run `npm run webdriver-update` and then `npm run e2e`
1. Update DSP-API version in `.github/workflows/main.yml` in step `Get api client test data from knora-api`, e.g., change `tags/v13.0.0-rc.16` to `tags/v13.0.0-rc.17`.
1. See if the tests pass on GitHub CI

## Integration of Generated Test Data
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
],
"scripts": {
"integrate-admin-test-data": "node scripts/integrate-files-admin.js",
"integrate-system-test-data": "node scripts/integrate-files-system.js",
"integrate-v2-test-data": "node scripts/integrate-files-v2.js",
"expand-jsonld-test-data": "node scripts/expand-jsonld-test-data-files.js",
"test": "karma start karma.conf.js",
Expand Down
21 changes: 21 additions & 0 deletions scripts/integrate-files-system.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"use strict";

const fs = require('fs-extra');

let pathToGeneratedCode;

// expect three args
if (process.argv.length !== 3) {
console.error("Usage: npm run integrate-system-code <generated client code>");
process.exit(1);
} else {
pathToGeneratedCode = process.argv[2];
if (!fs.existsSync(pathToGeneratedCode)) {
console.error("Specified path to generated client code is not valid");
process.exit(1);
}
}

fs.copySync(pathToGeneratedCode + "/system", "./test/data/api/system");

fs.moveSync('./test/data/api/system/health/response-headers.json', './test/data/api/system/health/response-headers.txt')
93 changes: 87 additions & 6 deletions src/api/system/health/health-endpoint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ describe("HealthEndpoint", () => {
const config = new KnoraApiConfig("http", "localhost", 3333, undefined, undefined, true);
const knoraApiConnection = new KnoraApiConnection(config);

const getServerFromResponseHeader = (resHeader: string) => {
// split by newline: first line server info, second line date
const headerParts = resHeader.split("\n");
// remove "Server: " from string
return headerParts[0].replace("Server: ", "");
}

beforeEach(() => {
jasmine.Ajax.install();
});
Expand All @@ -19,7 +26,7 @@ describe("HealthEndpoint", () => {

describe("Method getHealthStatus", () => {

it("should return health status", done => {
it("should return a running health status", done => {

knoraApiConnection.system.healthEndpoint.getHealthStatus().subscribe(
(response: ApiResponseData<HealthResponse>) => {
Expand All @@ -29,21 +36,95 @@ describe("HealthEndpoint", () => {
expect(response.body.severity).toEqual("non fatal");
expect(response.body.status).toEqual("healthy");

expect(response.body.webapiVersion).toEqual("v13.0.0-rc.16");
expect(response.body.webapiVersion).toEqual("v13.0.0-rc.21");
expect(response.body.akkaVersion).toEqual("10.1.12");

done();
});

const request = jasmine.Ajax.requests.mostRecent();

const health = require("../../../../test/data/api/system/health/running-response.json");

const responseHeader = require("../../../../test/data/api/system/health/response-headers.txt");

request.respondWith({
status: 200,
responseText: JSON.stringify(health),
responseHeaders: {
server: getServerFromResponseHeader(responseHeader)
}
});

expect(request.url).toBe("http://localhost:3333/health");

expect(request.method).toEqual("GET");

});

it("should return a maintenance mode health status", done => {

knoraApiConnection.system.healthEndpoint.getHealthStatus().subscribe(
(response: ApiResponseData<HealthResponse>) => {

expect(response.body.name).toEqual("AppState");
expect(response.body.message).toEqual("Application is in maintenance mode. Please retry later.");
expect(response.body.severity).toEqual("non fatal");
expect(response.body.status).toEqual("unhealthy");

expect(response.body.webapiVersion).toEqual("v13.0.0-rc.21");
expect(response.body.akkaVersion).toEqual("10.1.12");

done();
});

const request = jasmine.Ajax.requests.mostRecent();

const health = require("../../../../test/data/api/system/health/get-health-response.json");
const health = require("../../../../test/data/api/system/health/maintenance-mode-response.json");

const responseHeader = require("../../../../test/data/api/system/health/response-headers.txt");

request.respondWith({
status: 200,
responseText: JSON.stringify(health),
responseHeaders: {
server: getServerFromResponseHeader(responseHeader)
}
});

expect(request.url).toBe("http://localhost:3333/health");

expect(request.method).toEqual("GET");

});

it("should return a stopped mode health status", done => {

knoraApiConnection.system.healthEndpoint.getHealthStatus().subscribe(
(response: ApiResponseData<HealthResponse>) => {

expect(response.body.name).toEqual("AppState");
expect(response.body.message).toEqual("Stopped. Please retry later.");
expect(response.body.severity).toEqual("non fatal");
expect(response.body.status).toEqual("unhealthy");

expect(response.body.webapiVersion).toEqual("v13.0.0-rc.21");
expect(response.body.akkaVersion).toEqual("10.1.12");

done();
});

const request = jasmine.Ajax.requests.mostRecent();

const health = require("../../../../test/data/api/system/health/stopped-response.json");

const responseHeader = require("../../../../test/data/api/system/health/response-headers.txt");

request.respondWith({
status: 200,
responseText: JSON.stringify(health),
responseHeaders: {
server: "webapi/v13.0.0-rc.16 akka-http/10.1.12"
server: getServerFromResponseHeader(responseHeader)
}
});

Expand All @@ -65,7 +146,7 @@ describe("HealthEndpoint", () => {

const request = jasmine.Ajax.requests.mostRecent();

const health = require("../../../../test/data/api/system/health/get-health-response.json");
const health = require("../../../../test/data/api/system/health/running-response.json");

request.respondWith({
status: 200,
Expand All @@ -90,7 +171,7 @@ describe("HealthEndpoint", () => {

const request = jasmine.Ajax.requests.mostRecent();

const health = require("../../../../test/data/api/system/health/get-health-response.json");
const health = require("../../../../test/data/api/system/health/running-response.json");

request.respondWith({
status: 200,
Expand Down
6 changes: 0 additions & 6 deletions test/data/api/system/health/get-health-response.json

This file was deleted.

1 change: 1 addition & 0 deletions test/data/api/system/health/maintenance-mode-response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"message":"Application is in maintenance mode. Please retry later.","name":"AppState","severity":"non fatal","status":"unhealthy"}
2 changes: 2 additions & 0 deletions test/data/api/system/health/response-headers.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Server: webapi/v13.0.0-rc.21 akka-http/10.1.12
Date: Wed, 21 Oct 2020 23:41:38 GMT
1 change: 1 addition & 0 deletions test/data/api/system/health/running-response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"message":"Application is healthy","name":"AppState","severity":"non fatal","status":"healthy"}
1 change: 1 addition & 0 deletions test/data/api/system/health/stopped-response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"message":"Stopped. Please retry later.","name":"AppState","severity":"non fatal","status":"unhealthy"}

0 comments on commit f9914db

Please sign in to comment.