1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-25 12:15:18 +01:00

typemock lib for mocking services

This commit is contained in:
Kyle Spearrin 2018-04-21 12:57:29 -04:00
parent d73012efc8
commit cda2814192
3 changed files with 31 additions and 29 deletions

23
package-lock.json generated
View File

@ -979,6 +979,12 @@
} }
} }
}, },
"circular-json": {
"version": "0.3.3",
"resolved": "https://registry.npmjs.org/circular-json/-/circular-json-0.3.3.tgz",
"integrity": "sha512-UZK3NBx2Mca+b5LsG7bY183pHWt5Y1xts4P3Pz7ENTwGVnJOUWbRb3ocjvX7hx9tq/yTAdclXm9sZ38gNuem4A==",
"dev": true
},
"class-utils": { "class-utils": {
"version": "0.3.6", "version": "0.3.6",
"resolved": "https://registry.npmjs.org/class-utils/-/class-utils-0.3.6.tgz", "resolved": "https://registry.npmjs.org/class-utils/-/class-utils-0.3.6.tgz",
@ -6055,6 +6061,12 @@
"integrity": "sha1-AerA/jta9xoqbAL+q7jB/vfgDqs=", "integrity": "sha1-AerA/jta9xoqbAL+q7jB/vfgDqs=",
"dev": true "dev": true
}, },
"postinstall-build": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/postinstall-build/-/postinstall-build-5.0.1.tgz",
"integrity": "sha1-uRepB5smF42aJK9aXNjLSpkdEbk=",
"dev": true
},
"prelude-ls": { "prelude-ls": {
"version": "1.1.2", "version": "1.1.2",
"resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz",
@ -7828,6 +7840,17 @@
"mime-types": "2.1.18" "mime-types": "2.1.18"
} }
}, },
"typemoq": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/typemoq/-/typemoq-2.1.0.tgz",
"integrity": "sha512-DtRNLb7x8yCTv/KHlwes+NI+aGb4Vl1iPC63Hhtcvk1DpxSAZzKWQv0RQFY0jX2Uqj0SDBNl8Na4e6MV6TNDgw==",
"dev": true,
"requires": {
"circular-json": "0.3.3",
"lodash": "4.17.4",
"postinstall-build": "5.0.1"
}
},
"typescript": { "typescript": {
"version": "2.7.1", "version": "2.7.1",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-2.7.1.tgz", "resolved": "https://registry.npmjs.org/typescript/-/typescript-2.7.1.tgz",

View File

@ -45,6 +45,7 @@
"nodemon": "^1.17.3", "nodemon": "^1.17.3",
"rimraf": "^2.6.2", "rimraf": "^2.6.2",
"tslint": "^5.8.0", "tslint": "^5.8.0",
"typemoq": "^2.1.0",
"typescript": "^2.7.1" "typescript": "^2.7.1"
}, },
"dependencies": { "dependencies": {

View File

@ -1,3 +1,5 @@
import * as TypeMoq from 'typemoq';
import { DeviceType } from '../../../src/enums/deviceType'; import { DeviceType } from '../../../src/enums/deviceType';
import { PlatformUtilsService } from '../../../src/abstractions/platformUtils.service'; import { PlatformUtilsService } from '../../../src/abstractions/platformUtils.service';
@ -265,8 +267,9 @@ function testHmac(edge: boolean, algorithm: 'sha1' | 'sha256' | 'sha512', mac: s
} }
function getWebCryptoFunctionService(edge = false) { function getWebCryptoFunctionService(edge = false) {
const platformUtilsService = new BrowserPlatformUtilsService(edge); const platformUtilsMock = TypeMoq.Mock.ofType<PlatformUtilsService>(PlatformUtilsServiceMock);
return new WebCryptoFunctionService(window, platformUtilsService); platformUtilsMock.setup((x) => x.isEdge()).returns(() => edge);
return new WebCryptoFunctionService(window, platformUtilsMock.object);
} }
function makeStaticByteArray(length: number) { function makeStaticByteArray(length: number) {
@ -277,31 +280,6 @@ function makeStaticByteArray(length: number) {
return arr; return arr;
} }
class BrowserPlatformUtilsService implements PlatformUtilsService { class PlatformUtilsServiceMock extends PlatformUtilsService {
identityClientId: string; isEdge = () => false;
getDevice: () => DeviceType;
getDeviceString: () => string;
isFirefox: () => boolean;
isChrome: () => boolean;
isOpera: () => boolean;
isVivaldi: () => boolean;
isSafari: () => boolean;
isMacAppStore: () => boolean;
analyticsId: () => string;
getDomain: (uriString: string) => string;
isViewOpen: () => boolean;
launchUri: (uri: string, options?: any) => void;
saveFile: (win: Window, blobData: any, blobOptions: any, fileName: string) => void;
getApplicationVersion: () => string;
supportsU2f: (win: Window) => boolean;
showDialog: (text: string, title?: string, confirmText?: string, cancelText?: string,
type?: string) => Promise<boolean>;
isDev: () => boolean;
copyToClipboard: (text: string, options?: any) => void;
constructor(private edge: boolean) { }
isEdge() {
return this.edge;
}
} }