mirror of
https://github.com/hanzoai/firebase-js-sdk.git
synced 2026-09-24 16:59:10 +00:00
Refactor default exports into named exports (#622)
Following Google TS best practices.
This commit is contained in:
committed by
pinarx
parent
5320324014
commit
f090ce417a
@@ -15,8 +15,8 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
import WindowController from './src/controllers/window-controller';
|
||||
import SWController from './src/controllers/sw-controller';
|
||||
import { WindowController } from './src/controllers/window-controller';
|
||||
import { SWController } from './src/controllers/sw-controller';
|
||||
import { firebase } from '@firebase/app';
|
||||
import * as types from '@firebase/messaging-types';
|
||||
|
||||
|
||||
@@ -16,18 +16,18 @@
|
||||
'use strict';
|
||||
|
||||
import { ErrorFactory } from '@firebase/util';
|
||||
import Errors from '../models/errors';
|
||||
import TokenDetailsModel from '../models/token-details-model';
|
||||
import VapidDetailsModel from '../models/vapid-details-model';
|
||||
import NOTIFICATION_PERMISSION from '../models/notification-permission';
|
||||
import IIDModel from '../models/iid-model';
|
||||
import arrayBufferToBase64 from '../helpers/array-buffer-to-base64';
|
||||
import { ERROR_CODES, ERROR_MAP } from '../models/errors';
|
||||
import { TokenDetailsModel } from '../models/token-details-model';
|
||||
import { VapidDetailsModel } from '../models/vapid-details-model';
|
||||
import { NotificationPermission } from '../models/notification-permission';
|
||||
import { IIDModel } from '../models/iid-model';
|
||||
import { arrayBufferToBase64 } from '../helpers/array-buffer-to-base64';
|
||||
|
||||
const SENDER_ID_OPTION_NAME = 'messagingSenderId';
|
||||
// Database cache should be invalidated once a week.
|
||||
export const TOKEN_EXPIRATION_MILLIS = 7 * 24 * 60 * 60 * 1000; // 7 days
|
||||
|
||||
export default class ControllerInterface {
|
||||
export class ControllerInterface {
|
||||
public app;
|
||||
public INTERNAL;
|
||||
protected errorFactory_;
|
||||
@@ -41,13 +41,13 @@ export default class ControllerInterface {
|
||||
* @param {!firebase.app.App} app
|
||||
*/
|
||||
constructor(app) {
|
||||
this.errorFactory_ = new ErrorFactory('messaging', 'Messaging', Errors.map);
|
||||
this.errorFactory_ = new ErrorFactory('messaging', 'Messaging', ERROR_MAP);
|
||||
|
||||
if (
|
||||
!app.options[SENDER_ID_OPTION_NAME] ||
|
||||
typeof app.options[SENDER_ID_OPTION_NAME] !== 'string'
|
||||
) {
|
||||
throw this.errorFactory_.create(Errors.codes.BAD_SENDER_ID);
|
||||
throw this.errorFactory_.create(ERROR_CODES.BAD_SENDER_ID);
|
||||
}
|
||||
|
||||
this.messagingSenderId_ = app.options[SENDER_ID_OPTION_NAME];
|
||||
@@ -67,10 +67,10 @@ export default class ControllerInterface {
|
||||
async getToken(): Promise<string | null> {
|
||||
// Check with permissions
|
||||
const currentPermission = this.getNotificationPermission_();
|
||||
if (currentPermission !== NOTIFICATION_PERMISSION.granted) {
|
||||
if (currentPermission === NOTIFICATION_PERMISSION.denied) {
|
||||
if (currentPermission !== NotificationPermission.GRANTED) {
|
||||
if (currentPermission === NotificationPermission.DENIED) {
|
||||
return Promise.reject(
|
||||
this.errorFactory_.create(Errors.codes.NOTIFICATIONS_BLOCKED)
|
||||
this.errorFactory_.create(ERROR_CODES.NOTIFICATIONS_BLOCKED)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -262,11 +262,11 @@ export default class ControllerInterface {
|
||||
}
|
||||
|
||||
getSWRegistration_(): Promise<ServiceWorkerRegistration> {
|
||||
throw this.errorFactory_.create(Errors.codes.SHOULD_BE_INHERITED);
|
||||
throw this.errorFactory_.create(ERROR_CODES.SHOULD_BE_INHERITED);
|
||||
}
|
||||
|
||||
getPublicVapidKey_(): Promise<Uint8Array> {
|
||||
throw this.errorFactory_.create(Errors.codes.SHOULD_BE_INHERITED);
|
||||
throw this.errorFactory_.create(ERROR_CODES.SHOULD_BE_INHERITED);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -293,7 +293,7 @@ export default class ControllerInterface {
|
||||
//
|
||||
|
||||
requestPermission() {
|
||||
throw this.errorFactory_.create(Errors.codes.AVAILABLE_IN_WINDOW);
|
||||
throw this.errorFactory_.create(ERROR_CODES.AVAILABLE_IN_WINDOW);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -301,7 +301,7 @@ export default class ControllerInterface {
|
||||
* @param {!ServiceWorkerRegistration} registration
|
||||
*/
|
||||
useServiceWorker(registration) {
|
||||
throw this.errorFactory_.create(Errors.codes.AVAILABLE_IN_WINDOW);
|
||||
throw this.errorFactory_.create(ERROR_CODES.AVAILABLE_IN_WINDOW);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -309,7 +309,7 @@ export default class ControllerInterface {
|
||||
* @param {!string} b64PublicKey
|
||||
*/
|
||||
usePublicVapidKey(b64PublicKey) {
|
||||
throw this.errorFactory_.create(Errors.codes.AVAILABLE_IN_WINDOW);
|
||||
throw this.errorFactory_.create(ERROR_CODES.AVAILABLE_IN_WINDOW);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -320,7 +320,7 @@ export default class ControllerInterface {
|
||||
* @return {!function()}
|
||||
*/
|
||||
onMessage(nextOrObserver, optError, optCompleted) {
|
||||
throw this.errorFactory_.create(Errors.codes.AVAILABLE_IN_WINDOW);
|
||||
throw this.errorFactory_.create(ERROR_CODES.AVAILABLE_IN_WINDOW);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -334,7 +334,7 @@ export default class ControllerInterface {
|
||||
* @return {!function()} The unsubscribe function for the observer.
|
||||
*/
|
||||
onTokenRefresh(nextOrObserver, optError, optCompleted) {
|
||||
throw this.errorFactory_.create(Errors.codes.AVAILABLE_IN_WINDOW);
|
||||
throw this.errorFactory_.create(ERROR_CODES.AVAILABLE_IN_WINDOW);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -346,7 +346,7 @@ export default class ControllerInterface {
|
||||
* @param {function(Object)} callback
|
||||
*/
|
||||
setBackgroundMessageHandler(callback) {
|
||||
throw this.errorFactory_.create(Errors.codes.AVAILABLE_IN_SW);
|
||||
throw this.errorFactory_.create(ERROR_CODES.AVAILABLE_IN_SW);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@@ -15,14 +15,14 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
import ControllerInterface from './controller-interface';
|
||||
import Errors from '../models/errors';
|
||||
import FCMDetails from '../models/fcm-details';
|
||||
import { ControllerInterface } from './controller-interface';
|
||||
import { ERROR_CODES } from '../models/errors';
|
||||
import { DEFAULT_PUBLIC_VAPID_KEY } from '../models/fcm-details';
|
||||
import WorkerPageMessage from '../models/worker-page-message';
|
||||
|
||||
const FCM_MSG = 'FCM_MSG';
|
||||
|
||||
export default class SWController extends ControllerInterface {
|
||||
export class SWController extends ControllerInterface {
|
||||
private bgMessageHandler_: (input: Object) => Promise<any>;
|
||||
|
||||
constructor(app) {
|
||||
@@ -128,7 +128,7 @@ export default class SWController extends ControllerInterface {
|
||||
});
|
||||
})
|
||||
.catch(err => {
|
||||
throw this.errorFactory_.create(Errors.codes.UNABLE_TO_RESUBSCRIBE, {
|
||||
throw this.errorFactory_.create(ERROR_CODES.UNABLE_TO_RESUBSCRIBE, {
|
||||
message: err
|
||||
});
|
||||
});
|
||||
@@ -242,9 +242,7 @@ export default class SWController extends ControllerInterface {
|
||||
*/
|
||||
setBackgroundMessageHandler(callback) {
|
||||
if (!callback || typeof callback !== 'function') {
|
||||
throw this.errorFactory_.create(
|
||||
Errors.codes.BG_HANDLER_FUNCTION_EXPECTED
|
||||
);
|
||||
throw this.errorFactory_.create(ERROR_CODES.BG_HANDLER_FUNCTION_EXPECTED);
|
||||
}
|
||||
|
||||
this.bgMessageHandler_ = callback;
|
||||
@@ -301,7 +299,7 @@ export default class SWController extends ControllerInterface {
|
||||
// do additional work
|
||||
if (!client) {
|
||||
return Promise.reject(
|
||||
this.errorFactory_.create(Errors.codes.NO_WINDOW_CLIENT_TO_MSG)
|
||||
this.errorFactory_.create(ERROR_CODES.NO_WINDOW_CLIENT_TO_MSG)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -372,7 +370,7 @@ export default class SWController extends ControllerInterface {
|
||||
})
|
||||
.then(vapidKeyFromDatabase => {
|
||||
if (vapidKeyFromDatabase === null) {
|
||||
return FCMDetails.DEFAULT_PUBLIC_VAPID_KEY;
|
||||
return DEFAULT_PUBLIC_VAPID_KEY;
|
||||
}
|
||||
return vapidKeyFromDatabase;
|
||||
});
|
||||
|
||||
@@ -16,18 +16,18 @@
|
||||
'use strict';
|
||||
|
||||
import { FirebaseMessaging } from '@firebase/messaging-types';
|
||||
import ControllerInterface from './controller-interface';
|
||||
import Errors from '../models/errors';
|
||||
import { ControllerInterface } from './controller-interface';
|
||||
import { ERROR_CODES } from '../models/errors';
|
||||
import WorkerPageMessage from '../models/worker-page-message';
|
||||
import DefaultSW from '../models/default-sw';
|
||||
import NOTIFICATION_PERMISSION from '../models/notification-permission';
|
||||
import FCMDetails from '../models/fcm-details';
|
||||
import base64ToArrayBuffer from '../helpers/base64-to-array-buffer';
|
||||
import { DEFAULT_SW_PATH, DEFAULT_SW_SCOPE } from '../models/default-sw';
|
||||
import { NotificationPermission } from '../models/notification-permission';
|
||||
import { DEFAULT_PUBLIC_VAPID_KEY } from '../models/fcm-details';
|
||||
import { base64ToArrayBuffer } from '../helpers/base64-to-array-buffer';
|
||||
import { createSubscribe } from '@firebase/util';
|
||||
|
||||
declare const firebase: any;
|
||||
|
||||
export default class WindowController extends ControllerInterface
|
||||
export class WindowController extends ControllerInterface
|
||||
implements FirebaseMessaging {
|
||||
private registrationToUse_;
|
||||
private publicVapidKeyToUse_;
|
||||
@@ -99,7 +99,7 @@ export default class WindowController extends ControllerInterface
|
||||
// Check that the required API's are available
|
||||
if (!this.isSupported_()) {
|
||||
return Promise.reject(
|
||||
this.errorFactory_.create(Errors.codes.UNSUPPORTED_BROWSER)
|
||||
this.errorFactory_.create(ERROR_CODES.UNSUPPORTED_BROWSER)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ export default class WindowController extends ControllerInterface
|
||||
|
||||
if (manifestContent['gcm_sender_id'] !== '103953800507') {
|
||||
throw this.errorFactory_.create(
|
||||
Errors.codes.INCORRECT_GCM_SENDER_ID
|
||||
ERROR_CODES.INCORRECT_GCM_SENDER_ID
|
||||
);
|
||||
}
|
||||
});
|
||||
@@ -161,21 +161,21 @@ export default class WindowController extends ControllerInterface
|
||||
* rejects
|
||||
*/
|
||||
async requestPermission() {
|
||||
if ((Notification as any).permission === NOTIFICATION_PERMISSION.granted) {
|
||||
if ((Notification as any).permission === NotificationPermission.GRANTED) {
|
||||
return;
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const managePermissionResult = result => {
|
||||
if (result === NOTIFICATION_PERMISSION.granted) {
|
||||
if (result === NotificationPermission.GRANTED) {
|
||||
return resolve();
|
||||
} else if (result === NOTIFICATION_PERMISSION.denied) {
|
||||
} else if (result === NotificationPermission.DENIED) {
|
||||
return reject(
|
||||
this.errorFactory_.create(Errors.codes.PERMISSION_BLOCKED)
|
||||
this.errorFactory_.create(ERROR_CODES.PERMISSION_BLOCKED)
|
||||
);
|
||||
} else {
|
||||
return reject(
|
||||
this.errorFactory_.create(Errors.codes.PERMISSION_DEFAULT)
|
||||
this.errorFactory_.create(ERROR_CODES.PERMISSION_DEFAULT)
|
||||
);
|
||||
}
|
||||
};
|
||||
@@ -202,11 +202,11 @@ export default class WindowController extends ControllerInterface
|
||||
*/
|
||||
useServiceWorker(registration) {
|
||||
if (!(registration instanceof ServiceWorkerRegistration)) {
|
||||
throw this.errorFactory_.create(Errors.codes.SW_REGISTRATION_EXPECTED);
|
||||
throw this.errorFactory_.create(ERROR_CODES.SW_REGISTRATION_EXPECTED);
|
||||
}
|
||||
|
||||
if (typeof this.registrationToUse_ !== 'undefined') {
|
||||
throw this.errorFactory_.create(Errors.codes.USE_SW_BEFORE_GET_TOKEN);
|
||||
throw this.errorFactory_.create(ERROR_CODES.USE_SW_BEFORE_GET_TOKEN);
|
||||
}
|
||||
|
||||
this.registrationToUse_ = registration;
|
||||
@@ -220,21 +220,19 @@ export default class WindowController extends ControllerInterface
|
||||
*/
|
||||
usePublicVapidKey(publicKey) {
|
||||
if (typeof publicKey !== 'string') {
|
||||
throw this.errorFactory_.create(Errors.codes.INVALID_PUBLIC_VAPID_KEY);
|
||||
throw this.errorFactory_.create(ERROR_CODES.INVALID_PUBLIC_VAPID_KEY);
|
||||
}
|
||||
|
||||
if (typeof this.publicVapidKeyToUse_ !== 'undefined') {
|
||||
throw this.errorFactory_.create(
|
||||
Errors.codes.USE_PUBLIC_KEY_BEFORE_GET_TOKEN
|
||||
ERROR_CODES.USE_PUBLIC_KEY_BEFORE_GET_TOKEN
|
||||
);
|
||||
}
|
||||
|
||||
const parsedKey = base64ToArrayBuffer(publicKey);
|
||||
|
||||
if (parsedKey.length !== 65) {
|
||||
throw this.errorFactory_.create(
|
||||
Errors.codes.PUBLIC_KEY_DECRYPTION_FAILED
|
||||
);
|
||||
throw this.errorFactory_.create(ERROR_CODES.PUBLIC_KEY_DECRYPTION_FAILED);
|
||||
}
|
||||
|
||||
this.publicVapidKeyToUse_ = parsedKey;
|
||||
@@ -284,7 +282,7 @@ export default class WindowController extends ControllerInterface
|
||||
return new Promise<ServiceWorkerRegistration>((resolve, reject) => {
|
||||
if (!serviceWorker) {
|
||||
// This is a rare scenario but has occured in firefox
|
||||
reject(this.errorFactory_.create(Errors.codes.NO_SW_IN_REG));
|
||||
reject(this.errorFactory_.create(ERROR_CODES.NO_SW_IN_REG));
|
||||
return;
|
||||
}
|
||||
// Because the Promise function is called on next tick there is a
|
||||
@@ -295,7 +293,7 @@ export default class WindowController extends ControllerInterface
|
||||
}
|
||||
|
||||
if (serviceWorker.state === 'redundant') {
|
||||
reject(this.errorFactory_.create(Errors.codes.SW_REG_REDUNDANT));
|
||||
reject(this.errorFactory_.create(ERROR_CODES.SW_REG_REDUNDANT));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -303,7 +301,7 @@ export default class WindowController extends ControllerInterface
|
||||
if (serviceWorker.state === 'activated') {
|
||||
resolve(registration);
|
||||
} else if (serviceWorker.state === 'redundant') {
|
||||
reject(this.errorFactory_.create(Errors.codes.SW_REG_REDUNDANT));
|
||||
reject(this.errorFactory_.create(ERROR_CODES.SW_REG_REDUNDANT));
|
||||
} else {
|
||||
// Return early and wait to next state change
|
||||
return;
|
||||
@@ -330,12 +328,12 @@ export default class WindowController extends ControllerInterface
|
||||
this.registrationToUse_ = null;
|
||||
|
||||
return navigator.serviceWorker
|
||||
.register(DefaultSW.path, {
|
||||
scope: DefaultSW.scope
|
||||
.register(DEFAULT_SW_PATH, {
|
||||
scope: DEFAULT_SW_SCOPE
|
||||
})
|
||||
.catch(err => {
|
||||
throw this.errorFactory_.create(
|
||||
Errors.codes.FAILED_DEFAULT_REGISTRATION,
|
||||
ERROR_CODES.FAILED_DEFAULT_REGISTRATION,
|
||||
{
|
||||
browserErrorMessage: err.message
|
||||
}
|
||||
@@ -365,7 +363,7 @@ export default class WindowController extends ControllerInterface
|
||||
return Promise.resolve(this.publicVapidKeyToUse_);
|
||||
}
|
||||
|
||||
return Promise.resolve(FCMDetails.DEFAULT_PUBLIC_VAPID_KEY);
|
||||
return Promise.resolve(DEFAULT_PUBLIC_VAPID_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,15 +13,16 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
function toBase64(arrayBuffer) {
|
||||
const uint8Version = new Uint8Array(arrayBuffer);
|
||||
return window.btoa(String.fromCharCode.apply(null, uint8Version));
|
||||
}
|
||||
|
||||
export default arrayBuffer => {
|
||||
export function arrayBufferToBase64(arrayBuffer) {
|
||||
const base64String = toBase64(arrayBuffer);
|
||||
return base64String
|
||||
.replace(/=/g, '')
|
||||
.replace(/\+/g, '-')
|
||||
.replace(/\//g, '_');
|
||||
};
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export default base64String => {
|
||||
export function base64ToArrayBuffer(base64String) {
|
||||
const padding = '='.repeat((4 - base64String.length % 4) % 4);
|
||||
const base64 = (base64String + padding)
|
||||
.replace(/\-/g, '+')
|
||||
@@ -27,4 +27,4 @@ export default base64String => {
|
||||
outputArray[i] = rawData.charCodeAt(i);
|
||||
}
|
||||
return outputArray;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
* underlying tokens.
|
||||
*/
|
||||
|
||||
import IIDModel from '../models/iid-model';
|
||||
import { IIDModel } from '../models/iid-model';
|
||||
|
||||
const OLD_DB_NAME = 'undefined';
|
||||
const OLD_OBJECT_STORE_NAME = 'fcm_token_object_Store';
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
|
||||
import { ErrorFactory } from '@firebase/util';
|
||||
|
||||
import Errors from './errors';
|
||||
import { ERROR_CODES, ERROR_MAP } from './errors';
|
||||
|
||||
export default class DBInterface {
|
||||
export class DBInterface {
|
||||
private DB_NAME_: string;
|
||||
private dbVersion_: number;
|
||||
private openDbPromise_: Promise<IDBDatabase>;
|
||||
@@ -31,7 +31,7 @@ export default class DBInterface {
|
||||
* @param {number} dbVersion
|
||||
*/
|
||||
constructor(dbName, dbVersion) {
|
||||
this.errorFactory_ = new ErrorFactory('messaging', 'Messaging', Errors.map);
|
||||
this.errorFactory_ = new ErrorFactory('messaging', 'Messaging', ERROR_MAP);
|
||||
this.DB_NAME_ = dbName;
|
||||
this.dbVersion_ = dbVersion;
|
||||
this.openDbPromise_ = null;
|
||||
@@ -91,6 +91,6 @@ export default class DBInterface {
|
||||
* @param {!IDBDatabase} db
|
||||
*/
|
||||
onDBUpgrade(db: IDBDatabase, event: IDBVersionChangeEvent) {
|
||||
throw this.errorFactory_.create(Errors.codes.SHOULD_BE_INHERITED);
|
||||
throw this.errorFactory_.create(ERROR_CODES.SHOULD_BE_INHERITED);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,5 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
export default {
|
||||
path: '/firebase-messaging-sw.js',
|
||||
scope: '/firebase-cloud-messaging-push-scope'
|
||||
};
|
||||
export const DEFAULT_SW_PATH = '/firebase-messaging-sw.js';
|
||||
export const DEFAULT_SW_SCOPE = '/firebase-cloud-messaging-push-scope';
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
const CODES = {
|
||||
export const ERROR_CODES = {
|
||||
AVAILABLE_IN_WINDOW: 'only-available-in-window',
|
||||
AVAILABLE_IN_SW: 'only-available-in-sw',
|
||||
SHOULD_BE_INHERITED: 'should-be-overriden',
|
||||
@@ -57,97 +57,96 @@ const CODES = {
|
||||
PUBLIC_KEY_DECRYPTION_FAILED: 'public-vapid-key-decryption-failed'
|
||||
};
|
||||
|
||||
const ERROR_MAP = {
|
||||
[CODES.AVAILABLE_IN_WINDOW]: 'This method is available in a Window context.',
|
||||
[CODES.AVAILABLE_IN_SW]:
|
||||
export const ERROR_MAP = {
|
||||
[ERROR_CODES.AVAILABLE_IN_WINDOW]:
|
||||
'This method is available in a Window context.',
|
||||
[ERROR_CODES.AVAILABLE_IN_SW]:
|
||||
'This method is available in a service worker ' + 'context.',
|
||||
[CODES.SHOULD_BE_INHERITED]:
|
||||
[ERROR_CODES.SHOULD_BE_INHERITED]:
|
||||
'This method should be overriden by ' + 'extended classes.',
|
||||
[CODES.BAD_SENDER_ID]:
|
||||
[ERROR_CODES.BAD_SENDER_ID]:
|
||||
"Please ensure that 'messagingSenderId' is set " +
|
||||
'correctly in the options passed into firebase.initializeApp().',
|
||||
[CODES.PERMISSION_DEFAULT]:
|
||||
[ERROR_CODES.PERMISSION_DEFAULT]:
|
||||
'The required permissions were not granted and ' + 'dismissed instead.',
|
||||
[CODES.PERMISSION_BLOCKED]:
|
||||
[ERROR_CODES.PERMISSION_BLOCKED]:
|
||||
'The required permissions were not granted and ' + 'blocked instead.',
|
||||
[CODES.UNSUPPORTED_BROWSER]:
|
||||
[ERROR_CODES.UNSUPPORTED_BROWSER]:
|
||||
"This browser doesn't support the API's " +
|
||||
'required to use the firebase SDK.',
|
||||
[CODES.NOTIFICATIONS_BLOCKED]: 'Notifications have been blocked.',
|
||||
[CODES.FAILED_DEFAULT_REGISTRATION]:
|
||||
[ERROR_CODES.NOTIFICATIONS_BLOCKED]: 'Notifications have been blocked.',
|
||||
[ERROR_CODES.FAILED_DEFAULT_REGISTRATION]:
|
||||
'We are unable to register the ' +
|
||||
'default service worker. {$browserErrorMessage}',
|
||||
[CODES.SW_REGISTRATION_EXPECTED]:
|
||||
[ERROR_CODES.SW_REGISTRATION_EXPECTED]:
|
||||
'A service worker registration was the ' + 'expected input.',
|
||||
[CODES.GET_SUBSCRIPTION_FAILED]:
|
||||
[ERROR_CODES.GET_SUBSCRIPTION_FAILED]:
|
||||
'There was an error when trying to get ' +
|
||||
'any existing Push Subscriptions.',
|
||||
[CODES.INVALID_SAVED_TOKEN]: 'Unable to access details of the saved token.',
|
||||
[CODES.SW_REG_REDUNDANT]:
|
||||
[ERROR_CODES.INVALID_SAVED_TOKEN]:
|
||||
'Unable to access details of the saved token.',
|
||||
[ERROR_CODES.SW_REG_REDUNDANT]:
|
||||
'The service worker being used for push was made ' + 'redundant.',
|
||||
[CODES.TOKEN_SUBSCRIBE_FAILED]:
|
||||
[ERROR_CODES.TOKEN_SUBSCRIBE_FAILED]:
|
||||
'A problem occured while subscribing the ' + 'user to FCM: {$message}',
|
||||
[CODES.TOKEN_SUBSCRIBE_NO_TOKEN]:
|
||||
[ERROR_CODES.TOKEN_SUBSCRIBE_NO_TOKEN]:
|
||||
'FCM returned no token when subscribing ' + 'the user to push.',
|
||||
[CODES.TOKEN_SUBSCRIBE_NO_PUSH_SET]:
|
||||
[ERROR_CODES.TOKEN_SUBSCRIBE_NO_PUSH_SET]:
|
||||
'FCM returned an invalid response ' + 'when getting an FCM token.',
|
||||
[CODES.TOKEN_UNSUBSCRIBE_FAILED]:
|
||||
[ERROR_CODES.TOKEN_UNSUBSCRIBE_FAILED]:
|
||||
'A problem occured while unsubscribing the ' + 'user from FCM: {$message}',
|
||||
[CODES.TOKEN_UPDATE_FAILED]:
|
||||
[ERROR_CODES.TOKEN_UPDATE_FAILED]:
|
||||
'A problem occured while updating the ' + 'user from FCM: {$message}',
|
||||
[CODES.TOKEN_UPDATE_NO_TOKEN]:
|
||||
[ERROR_CODES.TOKEN_UPDATE_NO_TOKEN]:
|
||||
'FCM returned no token when updating ' + 'the user to push.',
|
||||
[CODES.USE_SW_BEFORE_GET_TOKEN]:
|
||||
[ERROR_CODES.USE_SW_BEFORE_GET_TOKEN]:
|
||||
'The useServiceWorker() method may only be called once and must be ' +
|
||||
'called before calling getToken() to ensure your service worker is used.',
|
||||
[CODES.INVALID_DELETE_TOKEN]:
|
||||
[ERROR_CODES.INVALID_DELETE_TOKEN]:
|
||||
'You must pass a valid token into ' +
|
||||
'deleteToken(), i.e. the token from getToken().',
|
||||
[CODES.DELETE_TOKEN_NOT_FOUND]:
|
||||
[ERROR_CODES.DELETE_TOKEN_NOT_FOUND]:
|
||||
'The deletion attempt for token could not ' +
|
||||
'be performed as the token was not found.',
|
||||
[CODES.DELETE_SCOPE_NOT_FOUND]:
|
||||
[ERROR_CODES.DELETE_SCOPE_NOT_FOUND]:
|
||||
'The deletion attempt for service worker ' +
|
||||
'scope could not be performed as the scope was not found.',
|
||||
[CODES.BG_HANDLER_FUNCTION_EXPECTED]:
|
||||
[ERROR_CODES.BG_HANDLER_FUNCTION_EXPECTED]:
|
||||
'The input to ' + 'setBackgroundMessageHandler() must be a function.',
|
||||
[CODES.NO_WINDOW_CLIENT_TO_MSG]:
|
||||
[ERROR_CODES.NO_WINDOW_CLIENT_TO_MSG]:
|
||||
'An attempt was made to message a ' + 'non-existant window client.',
|
||||
[CODES.UNABLE_TO_RESUBSCRIBE]:
|
||||
[ERROR_CODES.UNABLE_TO_RESUBSCRIBE]:
|
||||
'There was an error while re-subscribing ' +
|
||||
'the FCM token for push messaging. Will have to resubscribe the ' +
|
||||
'user on next visit. {$message}',
|
||||
[CODES.NO_FCM_TOKEN_FOR_RESUBSCRIBE]:
|
||||
[ERROR_CODES.NO_FCM_TOKEN_FOR_RESUBSCRIBE]:
|
||||
'Could not find an FCM token ' +
|
||||
'and as a result, unable to resubscribe. Will have to resubscribe the ' +
|
||||
'user on next visit.',
|
||||
[CODES.FAILED_TO_DELETE_TOKEN]: 'Unable to delete the currently saved token.',
|
||||
[CODES.NO_SW_IN_REG]:
|
||||
[ERROR_CODES.FAILED_TO_DELETE_TOKEN]:
|
||||
'Unable to delete the currently saved token.',
|
||||
[ERROR_CODES.NO_SW_IN_REG]:
|
||||
'Even though the service worker registration was ' +
|
||||
'successful, there was a problem accessing the service worker itself.',
|
||||
[CODES.INCORRECT_GCM_SENDER_ID]:
|
||||
[ERROR_CODES.INCORRECT_GCM_SENDER_ID]:
|
||||
"Please change your web app manifest's " +
|
||||
"'gcm_sender_id' value to '103953800507' to use Firebase messaging.",
|
||||
[CODES.BAD_SCOPE]:
|
||||
[ERROR_CODES.BAD_SCOPE]:
|
||||
'The service worker scope must be a string with at ' +
|
||||
'least one character.',
|
||||
[CODES.BAD_VAPID_KEY]:
|
||||
[ERROR_CODES.BAD_VAPID_KEY]:
|
||||
'The public VAPID key is not a Uint8Array with 65 bytes.',
|
||||
[CODES.BAD_SUBSCRIPTION]:
|
||||
[ERROR_CODES.BAD_SUBSCRIPTION]:
|
||||
'The subscription must be a valid ' + 'PushSubscription.',
|
||||
[CODES.BAD_TOKEN]:
|
||||
[ERROR_CODES.BAD_TOKEN]:
|
||||
'The FCM Token used for storage / lookup was not ' +
|
||||
'a valid token string.',
|
||||
[CODES.BAD_PUSH_SET]:
|
||||
[ERROR_CODES.BAD_PUSH_SET]:
|
||||
'The FCM push set used for storage / lookup was not ' +
|
||||
'not a valid push set string.',
|
||||
[CODES.FAILED_DELETE_VAPID_KEY]: 'The VAPID key could not be deleted.',
|
||||
[CODES.INVALID_PUBLIC_VAPID_KEY]: 'The public VAPID key must be a string.',
|
||||
[CODES.PUBLIC_KEY_DECRYPTION_FAILED]:
|
||||
[ERROR_CODES.FAILED_DELETE_VAPID_KEY]: 'The VAPID key could not be deleted.',
|
||||
[ERROR_CODES.INVALID_PUBLIC_VAPID_KEY]:
|
||||
'The public VAPID key must be a string.',
|
||||
[ERROR_CODES.PUBLIC_KEY_DECRYPTION_FAILED]:
|
||||
'The public VAPID key did not equal ' + '65 bytes when decrypted.'
|
||||
};
|
||||
|
||||
export default {
|
||||
codes: CODES,
|
||||
map: ERROR_MAP
|
||||
};
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
const DEFAULT_PUBLIC_VAPID_KEY = new Uint8Array([
|
||||
export const DEFAULT_PUBLIC_VAPID_KEY = new Uint8Array([
|
||||
0x04,
|
||||
0x33,
|
||||
0x94,
|
||||
@@ -83,14 +83,9 @@ const DEFAULT_PUBLIC_VAPID_KEY = new Uint8Array([
|
||||
0x6e
|
||||
]);
|
||||
|
||||
const SUBSCRIPTION_DETAILS = {
|
||||
export const SUBSCRIPTION_DETAILS = {
|
||||
userVisibleOnly: true,
|
||||
applicationServerKey: DEFAULT_PUBLIC_VAPID_KEY
|
||||
};
|
||||
|
||||
export default {
|
||||
DEFAULT_PUBLIC_VAPID_KEY,
|
||||
SUBSCRIPTION_DETAILS,
|
||||
ENDPOINT: 'https://fcm.googleapis.com'
|
||||
// ENDPOINT: 'https://jmt17.google.com'
|
||||
};
|
||||
export const ENDPOINT = 'https://fcm.googleapis.com';
|
||||
|
||||
@@ -18,15 +18,15 @@
|
||||
|
||||
import { ErrorFactory, base64 } from '@firebase/util';
|
||||
|
||||
import Errors from './errors';
|
||||
import arrayBufferToBase64 from '../helpers/array-buffer-to-base64';
|
||||
import FCMDetails from './fcm-details';
|
||||
import { ERROR_CODES, ERROR_MAP } from './errors';
|
||||
import { arrayBufferToBase64 } from '../helpers/array-buffer-to-base64';
|
||||
import { DEFAULT_PUBLIC_VAPID_KEY, ENDPOINT } from './fcm-details';
|
||||
|
||||
export default class IIDModel {
|
||||
export class IIDModel {
|
||||
private errorFactory_: ErrorFactory<string>;
|
||||
|
||||
constructor() {
|
||||
this.errorFactory_ = new ErrorFactory('messaging', 'Messaging', Errors.map);
|
||||
this.errorFactory_ = new ErrorFactory('messaging', 'Messaging', ERROR_MAP);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -48,7 +48,7 @@ export default class IIDModel {
|
||||
`encryption_key=${p256dh}&` +
|
||||
`encryption_auth=${auth}`;
|
||||
|
||||
if (publicVapidKey !== FCMDetails.DEFAULT_PUBLIC_VAPID_KEY) {
|
||||
if (publicVapidKey !== DEFAULT_PUBLIC_VAPID_KEY) {
|
||||
const applicationPubKey = arrayBufferToBase64(publicVapidKey);
|
||||
fcmSubscribeBody += `&application_pub_key=${applicationPubKey}`;
|
||||
}
|
||||
@@ -62,32 +62,27 @@ export default class IIDModel {
|
||||
body: fcmSubscribeBody
|
||||
};
|
||||
|
||||
return fetch(
|
||||
FCMDetails.ENDPOINT + '/fcm/connect/subscribe',
|
||||
subscribeOptions
|
||||
)
|
||||
return fetch(ENDPOINT + '/fcm/connect/subscribe', subscribeOptions)
|
||||
.then(response => response.json())
|
||||
.catch(() => {
|
||||
throw this.errorFactory_.create(Errors.codes.TOKEN_SUBSCRIBE_FAILED);
|
||||
throw this.errorFactory_.create(ERROR_CODES.TOKEN_SUBSCRIBE_FAILED);
|
||||
})
|
||||
.then(response => {
|
||||
const fcmTokenResponse = response;
|
||||
if (fcmTokenResponse['error']) {
|
||||
const message = fcmTokenResponse['error']['message'];
|
||||
throw this.errorFactory_.create(Errors.codes.TOKEN_SUBSCRIBE_FAILED, {
|
||||
throw this.errorFactory_.create(ERROR_CODES.TOKEN_SUBSCRIBE_FAILED, {
|
||||
message: message
|
||||
});
|
||||
}
|
||||
|
||||
if (!fcmTokenResponse['token']) {
|
||||
throw this.errorFactory_.create(
|
||||
Errors.codes.TOKEN_SUBSCRIBE_NO_TOKEN
|
||||
);
|
||||
throw this.errorFactory_.create(ERROR_CODES.TOKEN_SUBSCRIBE_NO_TOKEN);
|
||||
}
|
||||
|
||||
if (!fcmTokenResponse['pushSet']) {
|
||||
throw this.errorFactory_.create(
|
||||
Errors.codes.TOKEN_SUBSCRIBE_NO_PUSH_SET
|
||||
ERROR_CODES.TOKEN_SUBSCRIBE_NO_PUSH_SET
|
||||
);
|
||||
}
|
||||
|
||||
@@ -119,7 +114,7 @@ export default class IIDModel {
|
||||
`encryption_key=${p256dh}&` +
|
||||
`encryption_auth=${auth}`;
|
||||
|
||||
if (publicVapidKey !== FCMDetails.DEFAULT_PUBLIC_VAPID_KEY) {
|
||||
if (publicVapidKey !== DEFAULT_PUBLIC_VAPID_KEY) {
|
||||
const applicationPubKey = arrayBufferToBase64(publicVapidKey);
|
||||
fcmUpdateBody += `&application_pub_key=${applicationPubKey}`;
|
||||
}
|
||||
@@ -134,23 +129,23 @@ export default class IIDModel {
|
||||
};
|
||||
|
||||
let updateFetchRes;
|
||||
return fetch(FCMDetails.ENDPOINT + '/fcm/connect/subscribe', updateOptions)
|
||||
return fetch(ENDPOINT + '/fcm/connect/subscribe', updateOptions)
|
||||
.then(fetchResponse => {
|
||||
updateFetchRes = fetchResponse;
|
||||
return fetchResponse.json();
|
||||
})
|
||||
.catch(() => {
|
||||
throw this.errorFactory_.create(Errors.codes.TOKEN_UPDATE_FAILED);
|
||||
throw this.errorFactory_.create(ERROR_CODES.TOKEN_UPDATE_FAILED);
|
||||
})
|
||||
.then(fcmTokenResponse => {
|
||||
if (!updateFetchRes.ok) {
|
||||
const message = fcmTokenResponse['error']['message'];
|
||||
throw this.errorFactory_.create(Errors.codes.TOKEN_UPDATE_FAILED, {
|
||||
throw this.errorFactory_.create(ERROR_CODES.TOKEN_UPDATE_FAILED, {
|
||||
message: message
|
||||
});
|
||||
}
|
||||
if (!fcmTokenResponse['token']) {
|
||||
throw this.errorFactory_.create(Errors.codes.TOKEN_UPDATE_NO_TOKEN);
|
||||
throw this.errorFactory_.create(ERROR_CODES.TOKEN_UPDATE_NO_TOKEN);
|
||||
}
|
||||
return fcmTokenResponse['token'];
|
||||
});
|
||||
@@ -179,7 +174,7 @@ export default class IIDModel {
|
||||
};
|
||||
|
||||
return fetch(
|
||||
FCMDetails.ENDPOINT + '/fcm/connect/unsubscribe',
|
||||
ENDPOINT + '/fcm/connect/unsubscribe',
|
||||
unsubscribeOptions
|
||||
).then(fetchResponse => {
|
||||
if (!fetchResponse.ok) {
|
||||
@@ -188,7 +183,7 @@ export default class IIDModel {
|
||||
if (fcmTokenResponse['error']) {
|
||||
const message = fcmTokenResponse['error']['message'];
|
||||
throw this.errorFactory_.create(
|
||||
Errors.codes.TOKEN_UNSUBSCRIBE_FAILED,
|
||||
ERROR_CODES.TOKEN_UNSUBSCRIBE_FAILED,
|
||||
{
|
||||
message: message
|
||||
}
|
||||
@@ -197,7 +192,7 @@ export default class IIDModel {
|
||||
},
|
||||
err => {
|
||||
throw this.errorFactory_.create(
|
||||
Errors.codes.TOKEN_UNSUBSCRIBE_FAILED
|
||||
ERROR_CODES.TOKEN_UNSUBSCRIBE_FAILED
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
export default {
|
||||
granted: 'granted',
|
||||
default: 'default',
|
||||
denied: 'denied'
|
||||
};
|
||||
export enum NotificationPermission {
|
||||
DEFAULT = 'default',
|
||||
GRANTED = 'granted',
|
||||
DENIED = 'denied'
|
||||
}
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
import DBInterface from './db-interface';
|
||||
import Errors from './errors';
|
||||
import arrayBufferToBase64 from '../helpers/array-buffer-to-base64';
|
||||
import { DBInterface } from './db-interface';
|
||||
import { ERROR_CODES } from './errors';
|
||||
import { arrayBufferToBase64 } from '../helpers/array-buffer-to-base64';
|
||||
import { cleanV1 } from './clean-v1-undefined';
|
||||
|
||||
const FCM_TOKEN_OBJ_STORE = 'fcm_token_object_Store';
|
||||
@@ -39,7 +39,7 @@ ValidateInput.prototype.fcmSenderId;
|
||||
/** @type {string|undefined} */
|
||||
ValidateInput.prototype.fcmPushSet;
|
||||
|
||||
export default class TokenDetailsModel extends DBInterface {
|
||||
export class TokenDetailsModel extends DBInterface {
|
||||
constructor() {
|
||||
super(DB_NAME, DB_VERSION);
|
||||
}
|
||||
@@ -80,17 +80,13 @@ export default class TokenDetailsModel extends DBInterface {
|
||||
async validateInputs_(input) {
|
||||
if (input.fcmToken) {
|
||||
if (typeof input.fcmToken !== 'string' || input.fcmToken.length === 0) {
|
||||
return Promise.reject(
|
||||
this.errorFactory_.create(Errors.codes.BAD_TOKEN)
|
||||
);
|
||||
return Promise.reject(this.errorFactory_.create(ERROR_CODES.BAD_TOKEN));
|
||||
}
|
||||
}
|
||||
|
||||
if (input.swScope) {
|
||||
if (typeof input.swScope !== 'string' || input.swScope.length === 0) {
|
||||
return Promise.reject(
|
||||
this.errorFactory_.create(Errors.codes.BAD_SCOPE)
|
||||
);
|
||||
return Promise.reject(this.errorFactory_.create(ERROR_CODES.BAD_SCOPE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,7 +96,7 @@ export default class TokenDetailsModel extends DBInterface {
|
||||
input.vapidKey.length !== 65
|
||||
) {
|
||||
return Promise.reject(
|
||||
this.errorFactory_.create(Errors.codes.BAD_VAPID_KEY)
|
||||
this.errorFactory_.create(ERROR_CODES.BAD_VAPID_KEY)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -108,7 +104,7 @@ export default class TokenDetailsModel extends DBInterface {
|
||||
if (input.subscription) {
|
||||
if (!(input.subscription instanceof PushSubscription)) {
|
||||
return Promise.reject(
|
||||
this.errorFactory_.create(Errors.codes.BAD_SUBSCRIPTION)
|
||||
this.errorFactory_.create(ERROR_CODES.BAD_SUBSCRIPTION)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -119,7 +115,7 @@ export default class TokenDetailsModel extends DBInterface {
|
||||
input.fcmSenderId.length === 0
|
||||
) {
|
||||
return Promise.reject(
|
||||
this.errorFactory_.create(Errors.codes.BAD_SENDER_ID)
|
||||
this.errorFactory_.create(ERROR_CODES.BAD_SENDER_ID)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -130,7 +126,7 @@ export default class TokenDetailsModel extends DBInterface {
|
||||
input.fcmPushSet.length === 0
|
||||
) {
|
||||
return Promise.reject(
|
||||
this.errorFactory_.create(Errors.codes.BAD_PUSH_SET)
|
||||
this.errorFactory_.create(ERROR_CODES.BAD_PUSH_SET)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -143,7 +139,7 @@ export default class TokenDetailsModel extends DBInterface {
|
||||
*/
|
||||
getTokenDetailsFromToken(fcmToken) {
|
||||
if (!fcmToken) {
|
||||
return Promise.reject(this.errorFactory_.create(Errors.codes.BAD_TOKEN));
|
||||
return Promise.reject(this.errorFactory_.create(ERROR_CODES.BAD_TOKEN));
|
||||
}
|
||||
|
||||
return this.validateInputs_({ fcmToken })
|
||||
@@ -178,7 +174,7 @@ export default class TokenDetailsModel extends DBInterface {
|
||||
*/
|
||||
getTokenDetailsFromSWScope(swScope) {
|
||||
if (!swScope) {
|
||||
return Promise.reject(this.errorFactory_.create(Errors.codes.BAD_SCOPE));
|
||||
return Promise.reject(this.errorFactory_.create(ERROR_CODES.BAD_SCOPE));
|
||||
}
|
||||
|
||||
return this.validateInputs_({ swScope })
|
||||
@@ -220,34 +216,34 @@ export default class TokenDetailsModel extends DBInterface {
|
||||
fcmPushSet
|
||||
}) {
|
||||
if (!swScope) {
|
||||
return Promise.reject(this.errorFactory_.create(Errors.codes.BAD_SCOPE));
|
||||
return Promise.reject(this.errorFactory_.create(ERROR_CODES.BAD_SCOPE));
|
||||
}
|
||||
|
||||
if (!vapidKey) {
|
||||
return Promise.reject(
|
||||
this.errorFactory_.create(Errors.codes.BAD_VAPID_KEY)
|
||||
this.errorFactory_.create(ERROR_CODES.BAD_VAPID_KEY)
|
||||
);
|
||||
}
|
||||
|
||||
if (!subscription) {
|
||||
return Promise.reject(
|
||||
this.errorFactory_.create(Errors.codes.BAD_SUBSCRIPTION)
|
||||
this.errorFactory_.create(ERROR_CODES.BAD_SUBSCRIPTION)
|
||||
);
|
||||
}
|
||||
|
||||
if (!fcmSenderId) {
|
||||
return Promise.reject(
|
||||
this.errorFactory_.create(Errors.codes.BAD_SENDER_ID)
|
||||
this.errorFactory_.create(ERROR_CODES.BAD_SENDER_ID)
|
||||
);
|
||||
}
|
||||
|
||||
if (!fcmToken) {
|
||||
return Promise.reject(this.errorFactory_.create(Errors.codes.BAD_TOKEN));
|
||||
return Promise.reject(this.errorFactory_.create(ERROR_CODES.BAD_TOKEN));
|
||||
}
|
||||
|
||||
if (!fcmPushSet) {
|
||||
return Promise.reject(
|
||||
this.errorFactory_.create(Errors.codes.BAD_PUSH_SET)
|
||||
this.errorFactory_.create(ERROR_CODES.BAD_PUSH_SET)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -305,13 +301,13 @@ export default class TokenDetailsModel extends DBInterface {
|
||||
deleteToken(token: string) {
|
||||
if (typeof token !== 'string' || token.length === 0) {
|
||||
return Promise.reject(
|
||||
this.errorFactory_.create(Errors.codes.INVALID_DELETE_TOKEN)
|
||||
this.errorFactory_.create(ERROR_CODES.INVALID_DELETE_TOKEN)
|
||||
);
|
||||
}
|
||||
|
||||
return this.getTokenDetailsFromToken(token).then(details => {
|
||||
if (!details) {
|
||||
throw this.errorFactory_.create(Errors.codes.DELETE_TOKEN_NOT_FOUND);
|
||||
throw this.errorFactory_.create(ERROR_CODES.DELETE_TOKEN_NOT_FOUND);
|
||||
}
|
||||
|
||||
return this.openDatabase().then(db => {
|
||||
@@ -328,7 +324,7 @@ export default class TokenDetailsModel extends DBInterface {
|
||||
request.onsuccess = event => {
|
||||
if ((<IDBRequest>event.target).result === 0) {
|
||||
reject(
|
||||
this.errorFactory_.create(Errors.codes.FAILED_TO_DELETE_TOKEN)
|
||||
this.errorFactory_.create(ERROR_CODES.FAILED_TO_DELETE_TOKEN)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -15,15 +15,15 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
import DBInterface from './db-interface';
|
||||
import Errors from './errors';
|
||||
import { DBInterface } from './db-interface';
|
||||
import { ERROR_CODES } from './errors';
|
||||
|
||||
const FCM_VAPID_OBJ_STORE = 'fcm_vapid_object_Store';
|
||||
const DB_NAME = 'fcm_vapid_details_db';
|
||||
const DB_VERSION = 1;
|
||||
const UNCOMPRESSED_PUBLIC_KEY_SIZE = 65;
|
||||
|
||||
export default class VapidDetailsModel extends DBInterface {
|
||||
export class VapidDetailsModel extends DBInterface {
|
||||
constructor() {
|
||||
super(DB_NAME, DB_VERSION);
|
||||
}
|
||||
@@ -44,7 +44,7 @@ export default class VapidDetailsModel extends DBInterface {
|
||||
*/
|
||||
getVapidFromSWScope(swScope: string): Promise<Uint8Array> {
|
||||
if (typeof swScope !== 'string' || swScope.length === 0) {
|
||||
return Promise.reject(this.errorFactory_.create(Errors.codes.BAD_SCOPE));
|
||||
return Promise.reject(this.errorFactory_.create(ERROR_CODES.BAD_SCOPE));
|
||||
}
|
||||
|
||||
return this.openDatabase().then(db => {
|
||||
@@ -73,12 +73,12 @@ export default class VapidDetailsModel extends DBInterface {
|
||||
*/
|
||||
saveVapidDetails(swScope: string, vapidKey: Uint8Array): Promise<void> {
|
||||
if (typeof swScope !== 'string' || swScope.length === 0) {
|
||||
return Promise.reject(this.errorFactory_.create(Errors.codes.BAD_SCOPE));
|
||||
return Promise.reject(this.errorFactory_.create(ERROR_CODES.BAD_SCOPE));
|
||||
}
|
||||
|
||||
if (vapidKey === null || vapidKey.length !== UNCOMPRESSED_PUBLIC_KEY_SIZE) {
|
||||
return Promise.reject(
|
||||
this.errorFactory_.create(Errors.codes.BAD_VAPID_KEY)
|
||||
this.errorFactory_.create(ERROR_CODES.BAD_VAPID_KEY)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ export default class VapidDetailsModel extends DBInterface {
|
||||
deleteVapidDetails(swScope: string): Promise<Uint8Array> {
|
||||
return this.getVapidFromSWScope(swScope).then(vapidKey => {
|
||||
if (!vapidKey) {
|
||||
throw this.errorFactory_.create(Errors.codes.DELETE_SCOPE_NOT_FOUND);
|
||||
throw this.errorFactory_.create(ERROR_CODES.DELETE_SCOPE_NOT_FOUND);
|
||||
}
|
||||
|
||||
return this.openDatabase().then(db => {
|
||||
@@ -130,7 +130,7 @@ export default class VapidDetailsModel extends DBInterface {
|
||||
request.onsuccess = () => {
|
||||
if (request.result === 0) {
|
||||
reject(
|
||||
this.errorFactory_.create(Errors.codes.FAILED_DELETE_VAPID_KEY)
|
||||
this.errorFactory_.create(ERROR_CODES.FAILED_DELETE_VAPID_KEY)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
// These fields are strings to prevent closure from thinking goog.getMsg
|
||||
// should be used to initialise the values
|
||||
const PARAMS = {
|
||||
export const PARAMS = {
|
||||
TYPE_OF_MSG: 'firebase-messaging-msg-type',
|
||||
DATA: 'firebase-messaging-msg-data'
|
||||
};
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
import { expect } from 'chai';
|
||||
import arrayBufferToBase64 from '../src/helpers/array-buffer-to-base64';
|
||||
import { arrayBufferToBase64 } from '../src/helpers/array-buffer-to-base64';
|
||||
|
||||
describe('Firebase Messaging > array-buffer-to-base64', function() {
|
||||
it('should return expected value for p256dh example', function() {
|
||||
|
||||
@@ -15,11 +15,11 @@
|
||||
*/
|
||||
|
||||
import { assert } from 'chai';
|
||||
import makeFakeApp from './make-fake-app';
|
||||
import { makeFakeApp } from './make-fake-app';
|
||||
|
||||
import Errors from '../src/models/errors';
|
||||
import WindowController from '../src/controllers/window-controller';
|
||||
import SWController from '../src/controllers/sw-controller';
|
||||
import { ERROR_CODES } from '../src/models/errors';
|
||||
import { WindowController } from '../src/controllers/window-controller';
|
||||
import { SWController } from '../src/controllers/sw-controller';
|
||||
|
||||
describe('Firebase Messaging > new *Controller()', function() {
|
||||
it('should handle bad input', function() {
|
||||
@@ -51,7 +51,7 @@ describe('Firebase Messaging > new *Controller()', function() {
|
||||
} catch (err) {
|
||||
caughtError = err;
|
||||
}
|
||||
assert.equal('messaging/' + Errors.codes.BAD_SENDER_ID, caughtError.code);
|
||||
assert.equal('messaging/' + ERROR_CODES.BAD_SENDER_ID, caughtError.code);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -15,14 +15,14 @@
|
||||
*/
|
||||
import { assert } from 'chai';
|
||||
import * as sinon from 'sinon';
|
||||
import makeFakeApp from './make-fake-app';
|
||||
import makeFakeSWReg from './make-fake-sw-reg';
|
||||
import { makeFakeApp } from './make-fake-app';
|
||||
import { makeFakeSWReg } from './make-fake-sw-reg';
|
||||
import { deleteDatabase } from './testing-utils/db-helper';
|
||||
import Errors from '../src/models/errors';
|
||||
import TokenDetailsModel from '../src/models/token-details-model';
|
||||
import IIDModel from '../src/models/iid-model';
|
||||
import WindowController from '../src/controllers/window-controller';
|
||||
import SWController from '../src/controllers/sw-controller';
|
||||
import { ERROR_CODES } from '../src/models/errors';
|
||||
import { TokenDetailsModel } from '../src/models/token-details-model';
|
||||
import { IIDModel } from '../src/models/iid-model';
|
||||
import { WindowController } from '../src/controllers/window-controller';
|
||||
import { SWController } from '../src/controllers/sw-controller';
|
||||
|
||||
const EXAMPLE_TOKEN_SAVE = {
|
||||
fcmToken: 'ExampleFCMToken1337',
|
||||
@@ -90,10 +90,7 @@ describe('Firebase Messaging > *Controller.deleteToken()', function() {
|
||||
throw new Error('Expected error to be thrown.');
|
||||
},
|
||||
err => {
|
||||
assert.equal(
|
||||
'messaging/' + Errors.codes.INVALID_DELETE_TOKEN,
|
||||
err.code
|
||||
);
|
||||
assert.equal('messaging/' + ERROR_CODES.INVALID_DELETE_TOKEN, err.code);
|
||||
}
|
||||
);
|
||||
});
|
||||
@@ -212,7 +209,7 @@ describe('Firebase Messaging > *Controller.deleteToken()', function() {
|
||||
return Promise.resolve(EXAMPLE_TOKEN_SAVE);
|
||||
});
|
||||
|
||||
const errorMsg = 'messaging/' + Errors.codes.TOKEN_UNSUBSCRIBE_FAILED;
|
||||
const errorMsg = 'messaging/' + ERROR_CODES.TOKEN_UNSUBSCRIBE_FAILED;
|
||||
sandbox
|
||||
.stub(IIDModel.prototype, 'deleteToken')
|
||||
.callsFake(() => Promise.reject(new Error(errorMsg)));
|
||||
|
||||
@@ -13,25 +13,23 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { expect } from 'chai';
|
||||
import { assert } from 'chai';
|
||||
import { expect, assert } from 'chai';
|
||||
import * as sinon from 'sinon';
|
||||
import makeFakeApp from './make-fake-app';
|
||||
import makeFakeSWReg from './make-fake-sw-reg';
|
||||
import makeFakeSubscription from './make-fake-subscription';
|
||||
import Errors from '../src/models/errors';
|
||||
import WindowController from '../src/controllers/window-controller';
|
||||
import SWController from '../src/controllers/sw-controller';
|
||||
import ControllerInterface from '../src/controllers/controller-interface';
|
||||
import DefaultSW from '../src/models/default-sw';
|
||||
import FCMDetails from '../src/models/fcm-details';
|
||||
import TokenDetailsModel from '../src/models/token-details-model';
|
||||
import VapidDetailsModel from '../src/models/vapid-details-model';
|
||||
import IIDModel from '../src/models/iid-model';
|
||||
import NotificationPermission from '../src/models/notification-permission';
|
||||
import arrayBufferToBase64 from '../src/helpers/array-buffer-to-base64';
|
||||
import base64ToArrayBuffer from '../src/helpers/base64-to-array-buffer';
|
||||
import TOKEN_EXPIRATION_MILLIS from '../src/controllers/controller-interface';
|
||||
import { makeFakeApp } from './make-fake-app';
|
||||
import { makeFakeSWReg } from './make-fake-sw-reg';
|
||||
import { makeFakeSubscription } from './make-fake-subscription';
|
||||
import { ERROR_CODES } from '../src/models/errors';
|
||||
import { WindowController } from '../src/controllers/window-controller';
|
||||
import { SWController } from '../src/controllers/sw-controller';
|
||||
import { ControllerInterface } from '../src/controllers/controller-interface';
|
||||
import { DEFAULT_PUBLIC_VAPID_KEY } from '../src/models/fcm-details';
|
||||
import { TokenDetailsModel } from '../src/models/token-details-model';
|
||||
import { VapidDetailsModel } from '../src/models/vapid-details-model';
|
||||
import { IIDModel } from '../src/models/iid-model';
|
||||
import { NotificationPermission } from '../src/models/notification-permission';
|
||||
import { arrayBufferToBase64 } from '../src/helpers/array-buffer-to-base64';
|
||||
import { base64ToArrayBuffer } from '../src/helpers/base64-to-array-buffer';
|
||||
import { TOKEN_EXPIRATION_MILLIS } from '../src/controllers/controller-interface';
|
||||
|
||||
const ONE_DAY = 24 * 60 * 60 * 1000;
|
||||
|
||||
@@ -46,9 +44,7 @@ describe('Firebase Messaging > *Controller.getToken()', function() {
|
||||
const CUSTOM_VAPID_KEY =
|
||||
'BDd3_hVL9fZi9Ybo2UUzA284WG5FZR30_95YeZJsiApwXK' +
|
||||
'pNcF1rRPF3foIiBHXRdJI2Qhumhf6_LFTeZaNndIo';
|
||||
const DEFAULT_VAPID_KEY = arrayBufferToBase64(
|
||||
FCMDetails.DEFAULT_PUBLIC_VAPID_KEY
|
||||
);
|
||||
const DEFAULT_VAPID_KEY = arrayBufferToBase64(DEFAULT_PUBLIC_VAPID_KEY);
|
||||
|
||||
const EXAMPLE_TOKEN_DETAILS_DEFAULT_VAPID = {
|
||||
swScope: '/example-scope',
|
||||
@@ -147,7 +143,7 @@ describe('Firebase Messaging > *Controller.getToken()', function() {
|
||||
throw new Error('Expected getToken to throw ');
|
||||
},
|
||||
err => {
|
||||
assert.equal('messaging/' + Errors.codes.UNSUPPORTED_BROWSER, err.code);
|
||||
assert.equal('messaging/' + ERROR_CODES.UNSUPPORTED_BROWSER, err.code);
|
||||
}
|
||||
);
|
||||
});
|
||||
@@ -155,7 +151,7 @@ describe('Firebase Messaging > *Controller.getToken()', function() {
|
||||
it('should handle a failure to get registration', function() {
|
||||
sandbox
|
||||
.stub(ControllerInterface.prototype, 'getNotificationPermission_')
|
||||
.callsFake(() => NotificationPermission.granted);
|
||||
.callsFake(() => NotificationPermission.GRANTED);
|
||||
|
||||
sandbox
|
||||
.stub(navigator.serviceWorker, 'register')
|
||||
@@ -170,7 +166,7 @@ describe('Firebase Messaging > *Controller.getToken()', function() {
|
||||
},
|
||||
err => {
|
||||
assert.equal(
|
||||
'messaging/' + Errors.codes.FAILED_DEFAULT_REGISTRATION,
|
||||
'messaging/' + ERROR_CODES.FAILED_DEFAULT_REGISTRATION,
|
||||
err.code
|
||||
);
|
||||
}
|
||||
@@ -185,16 +181,16 @@ describe('Firebase Messaging > *Controller.getToken()', function() {
|
||||
ControllerInterface.prototype,
|
||||
'getNotificationPermission_'
|
||||
);
|
||||
notificationStub.onCall(0).returns(NotificationPermission.denied);
|
||||
notificationStub.onCall(1).returns(NotificationPermission.default);
|
||||
notificationStub.onCall(2).returns(NotificationPermission.denied);
|
||||
notificationStub.onCall(3).returns(NotificationPermission.default);
|
||||
notificationStub.onCall(0).returns(NotificationPermission.DENIED);
|
||||
notificationStub.onCall(1).returns(NotificationPermission.DEFAULT);
|
||||
notificationStub.onCall(2).returns(NotificationPermission.DENIED);
|
||||
notificationStub.onCall(3).returns(NotificationPermission.DEFAULT);
|
||||
|
||||
return servicesToTest.reduce((chain, ServiceClass) => {
|
||||
const serviceInstance = new ServiceClass(app);
|
||||
sandbox
|
||||
.stub(ServiceClass.prototype, 'getPublicVapidKey_')
|
||||
.callsFake(() => Promise.resolve(FCMDetails.DEFAULT_PUBLIC_VAPID_KEY));
|
||||
.callsFake(() => Promise.resolve(DEFAULT_PUBLIC_VAPID_KEY));
|
||||
return chain
|
||||
.then(() => {
|
||||
return serviceInstance.getToken();
|
||||
@@ -205,7 +201,7 @@ describe('Firebase Messaging > *Controller.getToken()', function() {
|
||||
},
|
||||
err => {
|
||||
assert.equal(
|
||||
'messaging/' + Errors.codes.NOTIFICATIONS_BLOCKED,
|
||||
'messaging/' + ERROR_CODES.NOTIFICATIONS_BLOCKED,
|
||||
err.code
|
||||
);
|
||||
}
|
||||
@@ -232,7 +228,7 @@ describe('Firebase Messaging > *Controller.getToken()', function() {
|
||||
.stub(ServiceClass.prototype, 'getPushSubscription')
|
||||
.callsFake(() => Promise.resolve(subscription));
|
||||
|
||||
let vapidKeyToUse = FCMDetails.DEFAULT_PUBLIC_VAPID_KEY;
|
||||
let vapidKeyToUse = DEFAULT_PUBLIC_VAPID_KEY;
|
||||
if (VapidSetup['name'] == 'custom') {
|
||||
vapidKeyToUse = base64ToArrayBuffer(CUSTOM_VAPID_KEY);
|
||||
}
|
||||
@@ -242,7 +238,7 @@ describe('Firebase Messaging > *Controller.getToken()', function() {
|
||||
|
||||
sandbox
|
||||
.stub(ControllerInterface.prototype, 'getNotificationPermission_')
|
||||
.callsFake(() => NotificationPermission.granted);
|
||||
.callsFake(() => NotificationPermission.GRANTED);
|
||||
|
||||
sandbox
|
||||
.stub(TokenDetailsModel.prototype, 'getTokenDetailsFromSWScope')
|
||||
@@ -273,7 +269,7 @@ describe('Firebase Messaging > *Controller.getToken()', function() {
|
||||
|
||||
sandbox
|
||||
.stub(ControllerInterface.prototype, 'getNotificationPermission_')
|
||||
.callsFake(() => NotificationPermission.granted);
|
||||
.callsFake(() => NotificationPermission.GRANTED);
|
||||
|
||||
sandbox
|
||||
.stub(TokenDetailsModel.prototype, 'getTokenDetailsFromSWScope')
|
||||
@@ -294,7 +290,7 @@ describe('Firebase Messaging > *Controller.getToken()', function() {
|
||||
|
||||
sandbox
|
||||
.stub(ControllerInterface.prototype, 'getNotificationPermission_')
|
||||
.callsFake(() => NotificationPermission.granted);
|
||||
.callsFake(() => NotificationPermission.GRANTED);
|
||||
|
||||
sandbox
|
||||
.stub(TokenDetailsModel.prototype, 'getTokenDetailsFromSWScope')
|
||||
@@ -302,7 +298,7 @@ describe('Firebase Messaging > *Controller.getToken()', function() {
|
||||
|
||||
sandbox
|
||||
.stub(ServiceClass.prototype, 'getPublicVapidKey_')
|
||||
.callsFake(() => Promise.resolve(FCMDetails.DEFAULT_PUBLIC_VAPID_KEY));
|
||||
.callsFake(() => Promise.resolve(DEFAULT_PUBLIC_VAPID_KEY));
|
||||
|
||||
sandbox
|
||||
.stub(ServiceClass.prototype, 'getPushSubscription')
|
||||
@@ -341,13 +337,13 @@ describe('Firebase Messaging > *Controller.getToken()', function() {
|
||||
|
||||
sandbox
|
||||
.stub(ControllerInterface.prototype, 'getNotificationPermission_')
|
||||
.callsFake(() => NotificationPermission.granted);
|
||||
.callsFake(() => NotificationPermission.GRANTED);
|
||||
|
||||
sandbox
|
||||
.stub(ServiceClass.prototype, 'getPushSubscription')
|
||||
.callsFake(() => Promise.resolve(subscription));
|
||||
|
||||
let vapidKeyToUse = FCMDetails.DEFAULT_PUBLIC_VAPID_KEY;
|
||||
let vapidKeyToUse = DEFAULT_PUBLIC_VAPID_KEY;
|
||||
if (VapidSetup['name'] === 'custom') {
|
||||
vapidKeyToUse = base64ToArrayBuffer(CUSTOM_VAPID_KEY);
|
||||
}
|
||||
@@ -421,10 +417,10 @@ describe('Firebase Messaging > *Controller.getToken()', function() {
|
||||
|
||||
sandbox
|
||||
.stub(ControllerInterface.prototype, 'getNotificationPermission_')
|
||||
.callsFake(() => NotificationPermission.granted);
|
||||
.callsFake(() => NotificationPermission.GRANTED);
|
||||
|
||||
const existingTokenDetails = VapidSetup['details'];
|
||||
let vapidKeyToUse = FCMDetails.DEFAULT_PUBLIC_VAPID_KEY;
|
||||
let vapidKeyToUse = DEFAULT_PUBLIC_VAPID_KEY;
|
||||
if (VapidSetup['name'] === 'custom') {
|
||||
vapidKeyToUse = base64ToArrayBuffer(CUSTOM_VAPID_KEY);
|
||||
}
|
||||
@@ -496,7 +492,7 @@ describe('Firebase Messaging > *Controller.getToken()', function() {
|
||||
|
||||
sandbox
|
||||
.stub(ControllerInterface.prototype, 'getNotificationPermission_')
|
||||
.callsFake(() => NotificationPermission.granted);
|
||||
.callsFake(() => NotificationPermission.GRANTED);
|
||||
|
||||
// start with using the deault key.
|
||||
const getPublicVapidKeyStub = sandbox.stub(
|
||||
@@ -505,12 +501,12 @@ describe('Firebase Messaging > *Controller.getToken()', function() {
|
||||
);
|
||||
|
||||
getPublicVapidKeyStub.callsFake(() =>
|
||||
Promise.resolve(FCMDetails.DEFAULT_PUBLIC_VAPID_KEY)
|
||||
Promise.resolve(DEFAULT_PUBLIC_VAPID_KEY)
|
||||
);
|
||||
|
||||
sandbox
|
||||
.stub(VapidDetailsModel.prototype, 'getVapidFromSWScope')
|
||||
.callsFake(() => Promise.resolve(FCMDetails.DEFAULT_PUBLIC_VAPID_KEY));
|
||||
.callsFake(() => Promise.resolve(DEFAULT_PUBLIC_VAPID_KEY));
|
||||
|
||||
sandbox
|
||||
.stub(VapidDetailsModel.prototype, 'saveVapidDetails')
|
||||
@@ -579,11 +575,11 @@ describe('Firebase Messaging > *Controller.getToken()', function() {
|
||||
const subscription = makeFakeSubscription();
|
||||
mockGetReg(Promise.resolve(registration));
|
||||
|
||||
const errorMsg = 'messaging/' + Errors.codes.TOKEN_UPDATE_FAILED;
|
||||
const errorMsg = 'messaging/' + ERROR_CODES.TOKEN_UPDATE_FAILED;
|
||||
|
||||
sandbox
|
||||
.stub(ControllerInterface.prototype, 'getNotificationPermission_')
|
||||
.callsFake(() => NotificationPermission.granted);
|
||||
.callsFake(() => NotificationPermission.GRANTED);
|
||||
|
||||
sandbox
|
||||
.stub(TokenDetailsModel.prototype, 'getTokenDetailsFromSWScope')
|
||||
@@ -595,11 +591,11 @@ describe('Firebase Messaging > *Controller.getToken()', function() {
|
||||
|
||||
sandbox
|
||||
.stub(ServiceClass.prototype, 'getPublicVapidKey_')
|
||||
.callsFake(() => Promise.resolve(FCMDetails.DEFAULT_PUBLIC_VAPID_KEY));
|
||||
.callsFake(() => Promise.resolve(DEFAULT_PUBLIC_VAPID_KEY));
|
||||
|
||||
sandbox
|
||||
.stub(VapidDetailsModel.prototype, 'getVapidFromSWScope')
|
||||
.callsFake(() => Promise.resolve(FCMDetails.DEFAULT_PUBLIC_VAPID_KEY));
|
||||
.callsFake(() => Promise.resolve(DEFAULT_PUBLIC_VAPID_KEY));
|
||||
|
||||
sandbox
|
||||
.stub(VapidDetailsModel.prototype, 'saveVapidDetails')
|
||||
|
||||
@@ -15,16 +15,16 @@
|
||||
*/
|
||||
import { expect } from 'chai';
|
||||
import * as sinon from 'sinon';
|
||||
import makeFakeApp from './make-fake-app';
|
||||
import makeFakeSWReg from './make-fake-sw-reg';
|
||||
import { makeFakeApp } from './make-fake-app';
|
||||
import { makeFakeSWReg } from './make-fake-sw-reg';
|
||||
|
||||
import FCMDetails from '../src/models/fcm-details';
|
||||
import WindowController from '../src/controllers/window-controller';
|
||||
import SWController from '../src/controllers/sw-controller';
|
||||
import ControllerInterface from '../src/controllers/controller-interface';
|
||||
import TokenDetailsModel from '../src/models/token-details-model';
|
||||
import VapidDetailsModel from '../src/models/vapid-details-model';
|
||||
import IIDModel from '../src/models/iid-model';
|
||||
import { DEFAULT_PUBLIC_VAPID_KEY } from '../src/models/fcm-details';
|
||||
import { WindowController } from '../src/controllers/window-controller';
|
||||
import { SWController } from '../src/controllers/sw-controller';
|
||||
import { ControllerInterface } from '../src/controllers/controller-interface';
|
||||
import { TokenDetailsModel } from '../src/models/token-details-model';
|
||||
import { VapidDetailsModel } from '../src/models/vapid-details-model';
|
||||
import { IIDModel } from '../src/models/iid-model';
|
||||
|
||||
const controllersToTest = [WindowController, SWController];
|
||||
|
||||
@@ -110,7 +110,7 @@ describe('Firebase Messaging > *ControllerInterface', function() {
|
||||
|
||||
const controller = new ControllerInTest(app);
|
||||
return controller
|
||||
.getPushSubscription(reg, FCMDetails.DEFAULT_PUBLIC_VAPID_KEY)
|
||||
.getPushSubscription(reg, DEFAULT_PUBLIC_VAPID_KEY)
|
||||
.then(
|
||||
() => {
|
||||
throw new Error('Expected an error.');
|
||||
@@ -130,7 +130,7 @@ describe('Firebase Messaging > *ControllerInterface', function() {
|
||||
|
||||
const controller = new ControllerInTest(app);
|
||||
return controller
|
||||
.getPushSubscription(reg, FCMDetails.DEFAULT_PUBLIC_VAPID_KEY)
|
||||
.getPushSubscription(reg, DEFAULT_PUBLIC_VAPID_KEY)
|
||||
.then(subscription => {
|
||||
expect(subscription).to.equal(exampleSubscription);
|
||||
});
|
||||
@@ -144,7 +144,7 @@ describe('Firebase Messaging > *ControllerInterface', function() {
|
||||
subscribe: options => {
|
||||
expect(options).to.deep.equal({
|
||||
userVisibleOnly: true,
|
||||
applicationServerKey: FCMDetails.DEFAULT_PUBLIC_VAPID_KEY
|
||||
applicationServerKey: DEFAULT_PUBLIC_VAPID_KEY
|
||||
});
|
||||
|
||||
return Promise.resolve(exampleSubscription);
|
||||
@@ -153,7 +153,7 @@ describe('Firebase Messaging > *ControllerInterface', function() {
|
||||
|
||||
const controller = new ControllerInTest(app);
|
||||
return controller
|
||||
.getPushSubscription(reg, FCMDetails.DEFAULT_PUBLIC_VAPID_KEY)
|
||||
.getPushSubscription(reg, DEFAULT_PUBLIC_VAPID_KEY)
|
||||
.then(subscription => {
|
||||
expect(subscription).to.equal(exampleSubscription);
|
||||
});
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
import { expect } from 'chai';
|
||||
import { deleteDatabase } from './testing-utils/db-helper';
|
||||
import DBInterface from '../src/models/db-interface';
|
||||
import { DBInterface } from '../src/models/db-interface';
|
||||
|
||||
describe(`Firebase Messaging > db-interface.onDBUpgrade()`, function() {
|
||||
const TEST_DB_NAME = 'test-db';
|
||||
|
||||
@@ -15,12 +15,11 @@
|
||||
*/
|
||||
import { assert } from 'chai';
|
||||
import * as sinon from 'sinon';
|
||||
import makeFakeApp from './make-fake-app';
|
||||
import makeFakeSWReg from './make-fake-sw-reg';
|
||||
import DefaultSW from '../src/models/default-sw';
|
||||
import Errors from '../src/models/errors';
|
||||
import WindowController from '../src/controllers/window-controller';
|
||||
import SWController from '../src/controllers/sw-controller';
|
||||
import { makeFakeApp } from './make-fake-app';
|
||||
import { makeFakeSWReg } from './make-fake-sw-reg';
|
||||
import { ERROR_CODES } from '../src/models/errors';
|
||||
import { WindowController } from '../src/controllers/window-controller';
|
||||
import { SWController } from '../src/controllers/sw-controller';
|
||||
|
||||
const EXAMPLE_SENDER_ID = '1234567890';
|
||||
|
||||
@@ -86,7 +85,7 @@ describe('Firebase Messaging > *Controller.getSWReg_()', function() {
|
||||
throw new Error('Expected this error to throw due to no SW.');
|
||||
},
|
||||
err => {
|
||||
assert.equal('messaging/' + Errors.codes.NO_SW_IN_REG, err.code);
|
||||
assert.equal('messaging/' + ERROR_CODES.NO_SW_IN_REG, err.code);
|
||||
}
|
||||
);
|
||||
});
|
||||
@@ -125,7 +124,7 @@ describe('Firebase Messaging > *Controller.getSWReg_()', function() {
|
||||
},
|
||||
error => {
|
||||
assert.equal(
|
||||
'messaging/' + Errors.codes.FAILED_DEFAULT_REGISTRATION,
|
||||
'messaging/' + ERROR_CODES.FAILED_DEFAULT_REGISTRATION,
|
||||
error.code
|
||||
);
|
||||
assert.equal(error.message.indexOf(errorMsg) !== -1, true);
|
||||
@@ -145,7 +144,7 @@ describe('Firebase Messaging > *Controller.getSWReg_()', function() {
|
||||
throw new Error('Should throw error due to redundant SW');
|
||||
},
|
||||
err => {
|
||||
assert.equal('messaging/' + Errors.codes.SW_REG_REDUNDANT, err.code);
|
||||
assert.equal('messaging/' + ERROR_CODES.SW_REG_REDUNDANT, err.code);
|
||||
}
|
||||
);
|
||||
});
|
||||
@@ -171,7 +170,7 @@ describe('Firebase Messaging > *Controller.getSWReg_()', function() {
|
||||
throw new Error('Should throw error due to redundant SW');
|
||||
},
|
||||
err => {
|
||||
assert.equal('messaging/' + Errors.codes.SW_REG_REDUNDANT, err.code);
|
||||
assert.equal('messaging/' + ERROR_CODES.SW_REG_REDUNDANT, err.code);
|
||||
}
|
||||
);
|
||||
});
|
||||
@@ -197,7 +196,7 @@ describe('Firebase Messaging > *Controller.getSWReg_()', function() {
|
||||
throw new Error('Should throw error due to redundant SW');
|
||||
},
|
||||
err => {
|
||||
assert.equal('messaging/' + Errors.codes.SW_REG_REDUNDANT, err.code);
|
||||
assert.equal('messaging/' + ERROR_CODES.SW_REG_REDUNDANT, err.code);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
*/
|
||||
import { expect } from 'chai';
|
||||
import * as sinon from 'sinon';
|
||||
import IIDModel from '../src/models/iid-model';
|
||||
import Errors from '../src/models/errors';
|
||||
import { IIDModel } from '../src/models/iid-model';
|
||||
import { ERROR_CODES } from '../src/models/errors';
|
||||
import { fetchMock } from './testing-utils/mock-fetch';
|
||||
|
||||
describe('Firebase Messaging > IIDModel.deleteToken()', function() {
|
||||
@@ -71,7 +71,7 @@ describe('Firebase Messaging > IIDModel.deleteToken()', function() {
|
||||
await globalIIDModel.deleteToken(fcmSenderId, fcmToken, fcmPushSet);
|
||||
throw new Error('Expected error to be thrown.');
|
||||
} catch (e) {
|
||||
expect(e.code).to.include(Errors.codes.TOKEN_UNSUBSCRIBE_FAILED);
|
||||
expect(e.code).to.include(ERROR_CODES.TOKEN_UNSUBSCRIBE_FAILED);
|
||||
}
|
||||
stubbedFetch.restore();
|
||||
});
|
||||
|
||||
@@ -15,11 +15,11 @@
|
||||
*/
|
||||
import { expect } from 'chai';
|
||||
import * as sinon from 'sinon';
|
||||
import IIDModel from '../src/models/iid-model';
|
||||
import Errors from '../src/models/errors';
|
||||
import { IIDModel } from '../src/models/iid-model';
|
||||
import { ERROR_CODES, ERROR_MAP } from '../src/models/errors';
|
||||
import { fetchMock } from './testing-utils/mock-fetch';
|
||||
import makeFakeSubscription from './make-fake-subscription';
|
||||
import FCMDetails from '../src/models/fcm-details';
|
||||
import { makeFakeSubscription } from './make-fake-subscription';
|
||||
import { DEFAULT_PUBLIC_VAPID_KEY } from '../src/models/fcm-details';
|
||||
|
||||
describe('Firebase Messaging > IIDModel.getToken()', function() {
|
||||
const fcmSenderId = '1234567';
|
||||
@@ -90,7 +90,7 @@ describe('Firebase Messaging > IIDModel.getToken()', function() {
|
||||
await globalIIDModel.getToken(
|
||||
fcmSenderId,
|
||||
subscription,
|
||||
FCMDetails.DEFAULT_PUBLIC_VAPID_KEY,
|
||||
DEFAULT_PUBLIC_VAPID_KEY,
|
||||
fcmPushSet
|
||||
);
|
||||
stubbedFetch.restore();
|
||||
@@ -128,7 +128,7 @@ describe('Firebase Messaging > IIDModel.getToken()', function() {
|
||||
);
|
||||
throw new Error('Expected error to be thrown.');
|
||||
} catch (e) {
|
||||
expect(e.code).to.include(Errors.codes.TOKEN_SUBSCRIBE_FAILED);
|
||||
expect(e.code).to.include(ERROR_CODES.TOKEN_SUBSCRIBE_FAILED);
|
||||
}
|
||||
stubbedFetch.restore();
|
||||
});
|
||||
@@ -150,7 +150,7 @@ describe('Firebase Messaging > IIDModel.getToken()', function() {
|
||||
throw new Error('Expected error to be thrown.');
|
||||
} catch (e) {
|
||||
expect(e.message).to.include(
|
||||
Errors.map[Errors.codes.TOKEN_SUBSCRIBE_NO_TOKEN]
|
||||
ERROR_MAP[ERROR_CODES.TOKEN_SUBSCRIBE_NO_TOKEN]
|
||||
);
|
||||
}
|
||||
stubbedFetch.restore();
|
||||
@@ -173,7 +173,7 @@ describe('Firebase Messaging > IIDModel.getToken()', function() {
|
||||
throw new Error('Expected error to be thrown.');
|
||||
} catch (e) {
|
||||
expect(e.message).to.include(
|
||||
Errors.map[Errors.codes.TOKEN_SUBSCRIBE_NO_PUSH_SET]
|
||||
ERROR_MAP[ERROR_CODES.TOKEN_SUBSCRIBE_NO_PUSH_SET]
|
||||
);
|
||||
}
|
||||
stubbedFetch.restore();
|
||||
|
||||
@@ -15,11 +15,11 @@
|
||||
*/
|
||||
import { expect } from 'chai';
|
||||
import * as sinon from 'sinon';
|
||||
import IIDModel from '../src/models/iid-model';
|
||||
import Errors from '../src/models/errors';
|
||||
import { IIDModel } from '../src/models/iid-model';
|
||||
import { ERROR_CODES, ERROR_MAP } from '../src/models/errors';
|
||||
import { fetchMock } from './testing-utils/mock-fetch';
|
||||
import makeFakeSubscription from './make-fake-subscription';
|
||||
import FCMDetails from '../src/models/fcm-details';
|
||||
import { makeFakeSubscription } from './make-fake-subscription';
|
||||
import { DEFAULT_PUBLIC_VAPID_KEY } from '../src/models/fcm-details';
|
||||
|
||||
describe('Firebase Messaging > IIDModel.deleteToken()', function() {
|
||||
const fcmSenderId = '1234567';
|
||||
@@ -71,7 +71,7 @@ describe('Firebase Messaging > IIDModel.deleteToken()', function() {
|
||||
fcmToken,
|
||||
fcmPushSet,
|
||||
subscription,
|
||||
FCMDetails.DEFAULT_PUBLIC_VAPID_KEY
|
||||
DEFAULT_PUBLIC_VAPID_KEY
|
||||
);
|
||||
stubbedFetch.restore();
|
||||
expect(res).to.equal(fcmToken);
|
||||
@@ -111,7 +111,7 @@ describe('Firebase Messaging > IIDModel.deleteToken()', function() {
|
||||
throw new Error('Expected error to be thrown.');
|
||||
} catch (e) {
|
||||
expect(e.message).to.include(
|
||||
Errors.map[Errors.codes.TOKEN_UPDATE_NO_TOKEN]
|
||||
ERROR_MAP[ERROR_CODES.TOKEN_UPDATE_NO_TOKEN]
|
||||
);
|
||||
}
|
||||
stubbedFetch.restore();
|
||||
@@ -131,7 +131,7 @@ describe('Firebase Messaging > IIDModel.deleteToken()', function() {
|
||||
);
|
||||
throw new Error('Expected error to be thrown.');
|
||||
} catch (e) {
|
||||
expect(e.code).to.include(Errors.codes.TOKEN_UPDATE_FAILED);
|
||||
expect(e.code).to.include(ERROR_CODES.TOKEN_UPDATE_FAILED);
|
||||
}
|
||||
stubbedFetch.restore();
|
||||
});
|
||||
|
||||
@@ -13,10 +13,11 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
export default (options = {}) => {
|
||||
|
||||
export function makeFakeApp(options = {}) {
|
||||
window['firebase'] = window['firebase'] || {};
|
||||
let app /** @type {!firebase.app.App} */ = {};
|
||||
(app as any).INTERNAL = window['firebase'].INTERNAL;
|
||||
(app as any).options = options;
|
||||
return app;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ const stringToArrayBuffer = string => {
|
||||
* @param {Object=} options Options to set on the object if desired.
|
||||
* @return {PushSubscription} Returns a fake subscription.
|
||||
*/
|
||||
export default function(options = {}) {
|
||||
export function makeFakeSubscription(options = {}) {
|
||||
const fakeSub = new FakeSubscription();
|
||||
|
||||
// Set endpoint
|
||||
|
||||
@@ -18,7 +18,7 @@ import * as sinon from 'sinon';
|
||||
const FakeRegistration = function() {};
|
||||
FakeRegistration.prototype = ServiceWorkerRegistration.prototype;
|
||||
|
||||
export default function(selectedState?, desiredValue?) {
|
||||
export function makeFakeSWReg(selectedState?, desiredValue?) {
|
||||
const fakeReg = new FakeRegistration();
|
||||
sinon.stub(fakeReg, 'scope').value('/injected-scope');
|
||||
const states = ['installing', 'waiting', 'active'];
|
||||
|
||||
@@ -15,13 +15,13 @@
|
||||
*/
|
||||
import { expect } from 'chai';
|
||||
import * as sinon from 'sinon';
|
||||
import makeFakeApp from './make-fake-app';
|
||||
import makeFakeSWReg from './make-fake-sw-reg';
|
||||
import { makeFakeApp } from './make-fake-app';
|
||||
import { makeFakeSWReg } from './make-fake-sw-reg';
|
||||
|
||||
import FCMDetails from '../src/models/fcm-details';
|
||||
import VapidDetailsModel from '../src/models/vapid-details-model';
|
||||
import base64ToArrayBuffer from '../src/helpers/base64-to-array-buffer';
|
||||
import SWController from '../src/controllers/sw-controller';
|
||||
import { DEFAULT_PUBLIC_VAPID_KEY } from '../src/models/fcm-details';
|
||||
import { VapidDetailsModel } from '../src/models/vapid-details-model';
|
||||
import { base64ToArrayBuffer } from '../src/helpers/base64-to-array-buffer';
|
||||
import { SWController } from '../src/controllers/sw-controller';
|
||||
|
||||
const VALID_VAPID_KEY =
|
||||
'BJzVfWqLoALJdgV20MYy6lrj0OfhmE16PI1qLIIYx2ZZL3FoQWJJL8L0rf7rS7tqd92j_3xN3fmejKK5Eb7yMYw';
|
||||
@@ -894,7 +894,7 @@ describe('Firebase Messaging > *SWController', function() {
|
||||
.stub(VapidDetailsModel.prototype, 'getVapidFromSWScope')
|
||||
.callsFake(() => Promise.resolve(null));
|
||||
return controller.getPublicVapidKey_().then(pubKey => {
|
||||
expect(pubKey).to.equal(FCMDetails.DEFAULT_PUBLIC_VAPID_KEY);
|
||||
expect(pubKey).to.equal(DEFAULT_PUBLIC_VAPID_KEY);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -903,9 +903,9 @@ describe('Firebase Messaging > *SWController', function() {
|
||||
const controller = new SWController(app);
|
||||
sandbox
|
||||
.stub(VapidDetailsModel.prototype, 'getVapidFromSWScope')
|
||||
.callsFake(() => Promise.resolve(FCMDetails.DEFAULT_PUBLIC_VAPID_KEY));
|
||||
.callsFake(() => Promise.resolve(DEFAULT_PUBLIC_VAPID_KEY));
|
||||
return controller.getPublicVapidKey_().then(pubKey => {
|
||||
expect(pubKey).to.equal(FCMDetails.DEFAULT_PUBLIC_VAPID_KEY);
|
||||
expect(pubKey).to.equal(DEFAULT_PUBLIC_VAPID_KEY);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
const deleteDatabase = dbName => {
|
||||
|
||||
export function deleteDatabase(dbName) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const request = indexedDB.deleteDatabase(dbName);
|
||||
request.onerror = event => {
|
||||
@@ -26,5 +27,4 @@ const deleteDatabase = dbName => {
|
||||
console.warn('deleteDb blocked.');
|
||||
};
|
||||
});
|
||||
};
|
||||
export { deleteDatabase };
|
||||
}
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import arrayBufferToBase64 from '../../src/helpers/array-buffer-to-base64';
|
||||
|
||||
import { arrayBufferToBase64 } from '../../src/helpers/array-buffer-to-base64';
|
||||
import { assert } from 'chai';
|
||||
|
||||
/** Token details that are fed to the database */
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
const fetchMock = {
|
||||
|
||||
export const fetchMock = {
|
||||
jsonOk: function(body: string): Promise<Response> {
|
||||
var mockResponse = new (window as any).Response(body, {
|
||||
status: 200,
|
||||
@@ -43,4 +44,3 @@ const fetchMock = {
|
||||
return Promise.resolve(mockResponse);
|
||||
}
|
||||
};
|
||||
export { fetchMock };
|
||||
|
||||
@@ -15,12 +15,12 @@
|
||||
*/
|
||||
import { assert } from 'chai';
|
||||
import * as sinon from 'sinon';
|
||||
import makeFakeSubscription from './make-fake-subscription';
|
||||
import { makeFakeSubscription } from './make-fake-subscription';
|
||||
import { deleteDatabase } from './testing-utils/db-helper';
|
||||
import Errors from '../src/models/errors';
|
||||
import TokenDetailsModel from '../src/models/token-details-model';
|
||||
import arrayBufferToBase64 from '../src/helpers/array-buffer-to-base64';
|
||||
import base64ToArrayBuffer from '../src/helpers/base64-to-array-buffer';
|
||||
import { ERROR_CODES } from '../src/models/errors';
|
||||
import { TokenDetailsModel } from '../src/models/token-details-model';
|
||||
import { arrayBufferToBase64 } from '../src/helpers/array-buffer-to-base64';
|
||||
import { base64ToArrayBuffer } from '../src/helpers/base64-to-array-buffer';
|
||||
import { compareDetails } from './testing-utils/detail-comparator';
|
||||
|
||||
describe('Firebase Messaging > TokenDetailsModel.deleteToken()', function() {
|
||||
@@ -65,10 +65,7 @@ describe('Firebase Messaging > TokenDetailsModel.deleteToken()', function() {
|
||||
throw new Error('Expected this to throw an error due to no token');
|
||||
},
|
||||
err => {
|
||||
assert.equal(
|
||||
'messaging/' + Errors.codes.INVALID_DELETE_TOKEN,
|
||||
err.code
|
||||
);
|
||||
assert.equal('messaging/' + ERROR_CODES.INVALID_DELETE_TOKEN, err.code);
|
||||
}
|
||||
);
|
||||
});
|
||||
@@ -80,10 +77,7 @@ describe('Firebase Messaging > TokenDetailsModel.deleteToken()', function() {
|
||||
throw new Error('Expected this to throw an error due to no token');
|
||||
},
|
||||
err => {
|
||||
assert.equal(
|
||||
'messaging/' + Errors.codes.INVALID_DELETE_TOKEN,
|
||||
err.code
|
||||
);
|
||||
assert.equal('messaging/' + ERROR_CODES.INVALID_DELETE_TOKEN, err.code);
|
||||
}
|
||||
);
|
||||
});
|
||||
@@ -117,7 +111,7 @@ describe('Firebase Messaging > TokenDetailsModel.deleteToken()', function() {
|
||||
},
|
||||
err => {
|
||||
assert.equal(
|
||||
'messaging/' + Errors.codes.DELETE_TOKEN_NOT_FOUND,
|
||||
'messaging/' + ERROR_CODES.DELETE_TOKEN_NOT_FOUND,
|
||||
err.code
|
||||
);
|
||||
}
|
||||
|
||||
@@ -15,12 +15,12 @@
|
||||
*/
|
||||
import { assert } from 'chai';
|
||||
import * as sinon from 'sinon';
|
||||
import makeFakeSubscription from './make-fake-subscription';
|
||||
import { makeFakeSubscription } from './make-fake-subscription';
|
||||
import { deleteDatabase } from './testing-utils/db-helper';
|
||||
import Errors from '../src/models/errors';
|
||||
import TokenDetailsModel from '../src/models/token-details-model';
|
||||
import arrayBufferToBase64 from '../src/helpers/array-buffer-to-base64';
|
||||
import base64ToArrayBuffer from '../src/helpers/base64-to-array-buffer';
|
||||
import { ERROR_CODES } from '../src/models/errors';
|
||||
import { TokenDetailsModel } from '../src/models/token-details-model';
|
||||
import { arrayBufferToBase64 } from '../src/helpers/array-buffer-to-base64';
|
||||
import { base64ToArrayBuffer } from '../src/helpers/base64-to-array-buffer';
|
||||
import { compareDetails } from './testing-utils/detail-comparator';
|
||||
|
||||
describe('Firebase Messaging > TokenDetailsModel.getTokenDetailsFromToken()', function() {
|
||||
@@ -67,7 +67,7 @@ describe('Firebase Messaging > TokenDetailsModel.getTokenDetailsFromToken()', fu
|
||||
throw new Error('Expected promise to reject');
|
||||
},
|
||||
err => {
|
||||
assert.equal('messaging/' + Errors.codes.BAD_SCOPE, err.code);
|
||||
assert.equal('messaging/' + ERROR_CODES.BAD_SCOPE, err.code);
|
||||
}
|
||||
);
|
||||
});
|
||||
@@ -81,7 +81,7 @@ describe('Firebase Messaging > TokenDetailsModel.getTokenDetailsFromToken()', fu
|
||||
throw new Error('Expected promise to reject');
|
||||
},
|
||||
err => {
|
||||
assert.equal('messaging/' + Errors.codes.BAD_TOKEN, err.code);
|
||||
assert.equal('messaging/' + ERROR_CODES.BAD_TOKEN, err.code);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
@@ -14,11 +14,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { assert } from 'chai';
|
||||
import makeFakeSubscription from './make-fake-subscription';
|
||||
import { makeFakeSubscription } from './make-fake-subscription';
|
||||
import { deleteDatabase } from './testing-utils/db-helper';
|
||||
import Errors from '../src/models/errors';
|
||||
import TokenDetailsModel from '../src/models/token-details-model';
|
||||
import base64ToArrayBuffer from '../src/helpers/base64-to-array-buffer';
|
||||
import { ERROR_CODES } from '../src/models/errors';
|
||||
import { TokenDetailsModel } from '../src/models/token-details-model';
|
||||
import { base64ToArrayBuffer } from '../src/helpers/base64-to-array-buffer';
|
||||
|
||||
describe('Firebase Messaging > TokenDetailsModel.saveToken()', function() {
|
||||
const EXAMPLE_INPUT = {
|
||||
@@ -66,7 +66,7 @@ describe('Firebase Messaging > TokenDetailsModel.saveToken()', function() {
|
||||
throw new Error('Expected promise to reject');
|
||||
},
|
||||
err => {
|
||||
assert.equal('messaging/' + Errors.codes.BAD_SCOPE, err.code);
|
||||
assert.equal('messaging/' + ERROR_CODES.BAD_SCOPE, err.code);
|
||||
}
|
||||
);
|
||||
});
|
||||
@@ -86,7 +86,7 @@ describe('Firebase Messaging > TokenDetailsModel.saveToken()', function() {
|
||||
throw new Error('Expected promise to reject');
|
||||
},
|
||||
err => {
|
||||
assert.equal('messaging/' + Errors.codes.BAD_VAPID_KEY, err.code);
|
||||
assert.equal('messaging/' + ERROR_CODES.BAD_VAPID_KEY, err.code);
|
||||
}
|
||||
);
|
||||
});
|
||||
@@ -106,7 +106,7 @@ describe('Firebase Messaging > TokenDetailsModel.saveToken()', function() {
|
||||
throw new Error('Expected promise to reject');
|
||||
},
|
||||
err => {
|
||||
assert.equal('messaging/' + Errors.codes.BAD_SUBSCRIPTION, err.code);
|
||||
assert.equal('messaging/' + ERROR_CODES.BAD_SUBSCRIPTION, err.code);
|
||||
}
|
||||
);
|
||||
});
|
||||
@@ -126,7 +126,7 @@ describe('Firebase Messaging > TokenDetailsModel.saveToken()', function() {
|
||||
throw new Error('Expected promise to reject');
|
||||
},
|
||||
err => {
|
||||
assert.equal('messaging/' + Errors.codes.BAD_SENDER_ID, err.code);
|
||||
assert.equal('messaging/' + ERROR_CODES.BAD_SENDER_ID, err.code);
|
||||
}
|
||||
);
|
||||
});
|
||||
@@ -146,7 +146,7 @@ describe('Firebase Messaging > TokenDetailsModel.saveToken()', function() {
|
||||
throw new Error('Expected promise to reject');
|
||||
},
|
||||
err => {
|
||||
assert.equal('messaging/' + Errors.codes.BAD_TOKEN, err.code);
|
||||
assert.equal('messaging/' + ERROR_CODES.BAD_TOKEN, err.code);
|
||||
}
|
||||
);
|
||||
});
|
||||
@@ -166,7 +166,7 @@ describe('Firebase Messaging > TokenDetailsModel.saveToken()', function() {
|
||||
throw new Error('Expected promise to reject');
|
||||
},
|
||||
err => {
|
||||
assert.equal('messaging/' + Errors.codes.BAD_PUSH_SET, err.code);
|
||||
assert.equal('messaging/' + ERROR_CODES.BAD_PUSH_SET, err.code);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
*/
|
||||
import { assert } from 'chai';
|
||||
import { deleteDatabase } from './testing-utils/db-helper';
|
||||
import Errors from '../src/models/errors';
|
||||
import VapidDetailsModel from '../src/models/vapid-details-model';
|
||||
import base64ToArrayBuffer from '../src/helpers/base64-to-array-buffer';
|
||||
import { ERROR_CODES } from '../src/models/errors';
|
||||
import { VapidDetailsModel } from '../src/models/vapid-details-model';
|
||||
import { base64ToArrayBuffer } from '../src/helpers/base64-to-array-buffer';
|
||||
|
||||
describe('Firebase Messaging > VapidDetailsModel.deleteToken()', function() {
|
||||
const EXAMPLE_SCOPE = '/example-scope';
|
||||
@@ -56,7 +56,7 @@ describe('Firebase Messaging > VapidDetailsModel.deleteToken()', function() {
|
||||
throw new Error('Expected promise to reject');
|
||||
},
|
||||
err => {
|
||||
assert.equal('messaging/' + Errors.codes.BAD_SCOPE, err.code);
|
||||
assert.equal('messaging/' + ERROR_CODES.BAD_SCOPE, err.code);
|
||||
}
|
||||
);
|
||||
});
|
||||
@@ -70,7 +70,7 @@ describe('Firebase Messaging > VapidDetailsModel.deleteToken()', function() {
|
||||
},
|
||||
err => {
|
||||
assert.equal(
|
||||
'messaging/' + Errors.codes.DELETE_SCOPE_NOT_FOUND,
|
||||
'messaging/' + ERROR_CODES.DELETE_SCOPE_NOT_FOUND,
|
||||
err.code
|
||||
);
|
||||
}
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
*/
|
||||
import { assert } from 'chai';
|
||||
import { deleteDatabase } from './testing-utils/db-helper';
|
||||
import Errors from '../src/models/errors';
|
||||
import VapidDetailsModel from '../src/models/vapid-details-model';
|
||||
import base64ToArrayBuffer from '../src/helpers/base64-to-array-buffer';
|
||||
import { ERROR_CODES } from '../src/models/errors';
|
||||
import { VapidDetailsModel } from '../src/models/vapid-details-model';
|
||||
import { base64ToArrayBuffer } from '../src/helpers/base64-to-array-buffer';
|
||||
|
||||
describe('Firebase Messaging > VapidDetailsModel.getVapidFromSWScope()', function() {
|
||||
const EXAMPLE_SCOPE = '/example-scope';
|
||||
@@ -56,7 +56,7 @@ describe('Firebase Messaging > VapidDetailsModel.getVapidFromSWScope()', functio
|
||||
throw new Error('Expected promise to reject');
|
||||
},
|
||||
err => {
|
||||
assert.equal('messaging/' + Errors.codes.BAD_SCOPE, err.code);
|
||||
assert.equal('messaging/' + ERROR_CODES.BAD_SCOPE, err.code);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
*/
|
||||
import { assert } from 'chai';
|
||||
import { deleteDatabase } from './testing-utils/db-helper';
|
||||
import Errors from '../src/models/errors';
|
||||
import VapidDetailsModel from '../src/models/vapid-details-model';
|
||||
import base64ToArrayBuffer from '../src/helpers/base64-to-array-buffer';
|
||||
import { ERROR_CODES } from '../src/models/errors';
|
||||
import { VapidDetailsModel } from '../src/models/vapid-details-model';
|
||||
import { base64ToArrayBuffer } from '../src/helpers/base64-to-array-buffer';
|
||||
|
||||
describe('Firebase Messaging > VapidDetailsModel.saveVapidDetails()', function() {
|
||||
const EXAMPLE_SCOPE = '/example-scope';
|
||||
@@ -56,7 +56,7 @@ describe('Firebase Messaging > VapidDetailsModel.saveVapidDetails()', function()
|
||||
throw new Error('Expected promise to reject');
|
||||
},
|
||||
err => {
|
||||
assert.equal('messaging/' + Errors.codes.BAD_SCOPE, err.code);
|
||||
assert.equal('messaging/' + ERROR_CODES.BAD_SCOPE, err.code);
|
||||
}
|
||||
);
|
||||
});
|
||||
@@ -71,7 +71,7 @@ describe('Firebase Messaging > VapidDetailsModel.saveVapidDetails()', function()
|
||||
throw new Error('Expected promise to reject');
|
||||
},
|
||||
err => {
|
||||
assert.equal('messaging/' + Errors.codes.BAD_VAPID_KEY, err.code);
|
||||
assert.equal('messaging/' + ERROR_CODES.BAD_VAPID_KEY, err.code);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
@@ -15,12 +15,12 @@
|
||||
*/
|
||||
import { expect } from 'chai';
|
||||
import * as sinon from 'sinon';
|
||||
import makeFakeApp from './make-fake-app';
|
||||
import makeFakeSWReg from './make-fake-sw-reg';
|
||||
import { makeFakeApp } from './make-fake-app';
|
||||
import { makeFakeSWReg } from './make-fake-sw-reg';
|
||||
|
||||
import FCMDetails from '../src/models/fcm-details';
|
||||
import base64ToArrayBuffer from '../src/helpers/base64-to-array-buffer';
|
||||
import WindowController from '../src/controllers/window-controller';
|
||||
import { DEFAULT_PUBLIC_VAPID_KEY } from '../src/models/fcm-details';
|
||||
import { base64ToArrayBuffer } from '../src/helpers/base64-to-array-buffer';
|
||||
import { WindowController } from '../src/controllers/window-controller';
|
||||
|
||||
const VALID_VAPID_KEY =
|
||||
'BJzVfWqLoALJdgV20MYy6lrj0OfhmE16PI1qLIIYx2ZZL3FoQWJJL8L0rf7rS7tqd92j_3xN3fmejKK5Eb7yMYw';
|
||||
@@ -333,7 +333,7 @@ describe('Firebase Messaging > *WindowController', function() {
|
||||
it('should return the default key by default', function() {
|
||||
const controller = new WindowController(app);
|
||||
return controller.getPublicVapidKey_().then(pubKey => {
|
||||
expect(pubKey).to.equal(FCMDetails.DEFAULT_PUBLIC_VAPID_KEY);
|
||||
expect(pubKey).to.equal(DEFAULT_PUBLIC_VAPID_KEY);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user