From 78d9d182842409dffb4e94fb0c14f0efb8c4dde3 Mon Sep 17 00:00:00 2001 From: Governikus Date: Tue, 7 Nov 2023 16:32:39 +0100 Subject: [PATCH] Add Test with future rename of json response to AusweisApp --- test/stationary-status-observer.spec.js | 4 +- test/stationary.spec.js | 62 +++++++++++++++++++------ 2 files changed, 51 insertions(+), 15 deletions(-) diff --git a/test/stationary-status-observer.spec.js b/test/stationary-status-observer.spec.js index 110e46b..6642701 100644 --- a/test/stationary-status-observer.spec.js +++ b/test/stationary-status-observer.spec.js @@ -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; @@ -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", }); diff --git a/test/stationary.spec.js b/test/stationary.spec.js index e583b41..364aba1 100644 --- a/test/stationary.spec.js +++ b/test/stationary.spec.js @@ -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(() => { @@ -27,16 +37,16 @@ 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) { @@ -44,7 +54,7 @@ describe("getStationaryStatus", function () { 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", @@ -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, }); @@ -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"); });