Skip to content

Commit

Permalink
Add Test with future rename of json response to AusweisApp
Browse files Browse the repository at this point in the history
  • Loading branch information
GovernikusAusweisApp2 committed Nov 7, 2023
1 parent 790b4e2 commit 78d9d18
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 15 deletions.
4 changes: 2 additions & 2 deletions test/stationary-status-observer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { StationaryStatusObserver } from "../src/stationary-status-observer.js";
describe("StationaryStatusObserver", function () {
var sso, cb;

var aa2AppUrl = "http://127.0.0.1:24727/eID-Client?Status=json";
var ausweisAppUrl = "http://127.0.0.1:24727/eID-Client?Status=json";

var originalFetch;

Expand Down Expand Up @@ -38,7 +38,7 @@ describe("StationaryStatusObserver", function () {
});

it("starts fetching the status", function (done) {
jasmine.Ajax.stubRequest(aa2AppUrl).andReturn({
jasmine.Ajax.stubRequest(ausweisAppUrl).andReturn({
status: 200,
statusText: "HTTP/1.0 200 OK",
});
Expand Down
62 changes: 49 additions & 13 deletions test/stationary.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,27 @@ import { fetch as fetchPolyfill } from "whatwg-fetch";
import { getStationaryStatus } from "../src/stationary.js";

describe("getStationaryStatus", function () {
var aa2AppUrl = "http://127.0.0.1:24727/eID-Client?Status=json";
var aa2StatusResponse = JSON.stringify({
var ausweisAppUrl = "http://127.0.0.1:24727/eID-Client?Status=json";
var ausweisAppStatusResponseLegacy = JSON.stringify({
"Implementation-Title": "AusweisApp2",
"Implementation-Vendor": "Governikus GmbH & Co. KG",
"Implementation-Version": "1.26.3",
"Implementation-Version": "1.26.4",
Name: "AusweisApp2",
"Specification-Title": "TR-03124",
"Specification-Vendor": "Federal Office for Information Security",
"Specification-Version": "1.3",
});

var ausweisAppStatusResponse = JSON.stringify({
"Implementation-Title": "AusweisApp",
"Implementation-Vendor": "Governikus GmbH & Co. KG",
"Implementation-Version": "2.0.0",
Name: "AusweisApp",
"Specification-Title": "TR-03124",
"Specification-Vendor": "Federal Office for Information Security",
"Specification-Version": "1.4",
});

var originalFetch;

beforeEach(() => {
Expand All @@ -27,24 +37,24 @@ describe("getStationaryStatus", function () {
window.fetch = originalFetch;
});

it("should emit the `available` status and return details, when the AA2 is running", function () {
jasmine.Ajax.stubRequest(aa2AppUrl).andReturn({
it("should emit the `available` status and return details, when the older AusweisApp version is running", function () {
jasmine.Ajax.stubRequest(ausweisAppUrl).andReturn({
status: 200,
statusText: "HTTP/1.0 200 OK",
contentType: "application/json",
responseHeaders: {
"access-control-allow-origin": "*",
server: "AusweisApp2/1.26.3 (TR-03124-1/1.3)",
server: "AusweisApp2/1.26.4 (TR-03124-1/1.3)",
},
response: aa2StatusResponse,
response: ausweisAppStatusResponseLegacy,
});

return getStationaryStatus().then(function (status) {
expect(status.status).toBe("available");
expect(status.details).toEqual({
implementationTitle: "AusweisApp2",
implementationVendor: "Governikus GmbH & Co. KG",
implementationVersion: "1.26.3",
implementationVersion: "1.26.4",
name: "AusweisApp2",
specificationTitle: "TR-03124",
specificationVendor: "Federal Office for Information Security",
Expand All @@ -53,16 +63,42 @@ describe("getStationaryStatus", function () {
});
});

it("should resolve the 'unavailable' status, when the AA2 does not respond", function () {
jasmine.Ajax.stubRequest(aa2AppUrl).andTimeout();
it("should emit the `available` status and return details, when the new AusweisApp version is running", function () {
jasmine.Ajax.stubRequest(ausweisAppUrl).andReturn({
status: 200,
statusText: "HTTP/1.0 200 OK",
contentType: "application/json",
responseHeaders: {
"access-control-allow-origin": "*",
server: "AusweisApp2/2.0.0 (TR-03124-1/1.4)",
},
response: ausweisAppStatusResponse,
});

return getStationaryStatus().then(function (status) {
expect(status.status).toBe("available");
expect(status.details).toEqual({
implementationTitle: "AusweisApp",
implementationVendor: "Governikus GmbH & Co. KG",
implementationVersion: "2.0.0",
name: "AusweisApp",
specificationTitle: "TR-03124",
specificationVendor: "Federal Office for Information Security",
specificationVersion: "1.4",
});
});
});

it("should resolve the 'unavailable' status, when the AusweisApp does not respond", function () {
jasmine.Ajax.stubRequest(ausweisAppUrl).andTimeout();

return getStationaryStatus().then(function (status) {
expect(status.status).toBe("unavailable");
});
});

it("should resolve the 'unavailable' status, when the AA2 responds with error status code", function () {
jasmine.Ajax.stubRequest(aa2AppUrl).andError({
it("should resolve the 'unavailable' status, when the AusweisApp responds with error status code", function () {
jasmine.Ajax.stubRequest(ausweisAppUrl).andError({
status: 404,
});

Expand All @@ -72,7 +108,7 @@ describe("getStationaryStatus", function () {
});

it("should resolve the 'unknown' status, when the browser blocks the fetch call", function () {
jasmine.Ajax.stubRequest(aa2AppUrl).andCallFunction(function () {
jasmine.Ajax.stubRequest(ausweisAppUrl).andCallFunction(function () {
throw new TypeError("Not allowed to request resource");
});

Expand Down

0 comments on commit 78d9d18

Please sign in to comment.