Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
feat(app-config): pwa validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Francois-Esquire authored Aug 20, 2020
1 parent 25dfadf commit fb10509
Show file tree
Hide file tree
Showing 13 changed files with 323 additions and 435 deletions.
27 changes: 1 addition & 26 deletions __tests__/server/middleware/pwa/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('pwa configuration', () => {
const serviceWorkerRecoveryScript = Buffer.from('[service-worker-noop-script]');
const serviceWorkerEscapeHatchScript = Buffer.from('self.unregister();');

beforeAll(() => {
beforeEach(() => {
process.env.ONE_SERVICE_WORKER = true;
});

Expand Down Expand Up @@ -131,8 +131,6 @@ describe('pwa configuration', () => {
serviceWorkerScriptUrl: false,
webManifestUrl: false,
});

process.env.ONE_SERVICE_WORKER = true;
});

test('disabling PWA configuration', () => {
Expand Down Expand Up @@ -184,29 +182,6 @@ describe('pwa configuration', () => {
});
});

test('using a function for the web manifest', () => {
configurePWA({
serviceWorker: true,
webManifest: () => ({
name: 'One App Test',
}),
});

expect(getServerPWAConfig()).toMatchObject({
webManifest: true,
serviceWorker: true,
serviceWorkerRecoveryMode: false,
serviceWorkerScope: '/',
});
expect(getClientPWAConfig()).toMatchObject({
serviceWorker: true,
serviceWorkerRecoveryMode: false,
serviceWorkerScope: '/',
serviceWorkerScriptUrl: '/_/pwa/service-worker.js',
webManifestUrl: '/_/pwa/manifest.webmanifest',
});
});

test('opting out of the web manifest', () => {
configurePWA({
serviceWorker: true,
Expand Down
190 changes: 0 additions & 190 deletions __tests__/server/middleware/pwa/validation.spec.js

This file was deleted.

72 changes: 72 additions & 0 deletions __tests__/server/utils/validation/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright 2020 American Express Travel Related Services Company, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

import { validatePWAConfig } from '../../../../src/server/utils/validation';

describe(validatePWAConfig.name, () => {
test('valid pwa config using a function', () => {
const clientUrl = 'https://example.com/api';
expect(
validatePWAConfig({
serviceWorker: true,
scope: '/',
webManifest: (config) => ({ name: 'One App Test', start_url: config.startUrl }),
}, {
clientStateConfig: {
startUrl: clientUrl,
},
})
).toEqual({
serviceWorker: true,
scope: '/',
webManifest: { name: 'One App Test', start_url: clientUrl },
});
});

test('invalid pwa config', () => {
expect(
() => validatePWAConfig({
serviceWorker: 'true',
escapeHatch: 0,
recoveryMode: [],
scope: '\\',
webManifest: {
short_name: /One App Test/,
start_url: '[start_url',
scope: 0,
display: 'sideways',
categories: ['pwa', 1234],
icons: [{
src: false,
}],
},
})
).toThrow(
new Error([
'"recoveryMode" must be a boolean',
'"escapeHatch" must be a boolean',
'"scope" must be a relative or absolute URL',
'"webManifest.name" is required',
'"webManifest.short_name" must be a string',
'"webManifest.scope" must be a string',
'"webManifest.start_url" must be a relative or absolute URL',
'"webManifest.categories[1]" must be a string',
'"webManifest.display" must be one of [fullscreen, standalone, minimal-ui, browser]',
'"webManifest.icons[0].src" must be a string',
].join('. '))
);
});
});
43 changes: 43 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"if-env": "^1.0.4",
"immutable": "^4.0.0-rc.12",
"ip": "^1.1.5",
"joi": "^17.2.0",
"lean-intl": "^4.2.2",
"make-promises-safe": "^5.1.0",
"matcher": "^3.0.0",
Expand Down
Loading

0 comments on commit fb10509

Please sign in to comment.