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:
parent
d73012efc8
commit
cda2814192
23
package-lock.json
generated
23
package-lock.json
generated
@ -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": {
|
||||
"version": "0.3.6",
|
||||
"resolved": "https://registry.npmjs.org/class-utils/-/class-utils-0.3.6.tgz",
|
||||
@ -6055,6 +6061,12 @@
|
||||
"integrity": "sha1-AerA/jta9xoqbAL+q7jB/vfgDqs=",
|
||||
"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": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz",
|
||||
@ -7828,6 +7840,17 @@
|
||||
"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": {
|
||||
"version": "2.7.1",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-2.7.1.tgz",
|
||||
|
@ -45,6 +45,7 @@
|
||||
"nodemon": "^1.17.3",
|
||||
"rimraf": "^2.6.2",
|
||||
"tslint": "^5.8.0",
|
||||
"typemoq": "^2.1.0",
|
||||
"typescript": "^2.7.1"
|
||||
},
|
||||
"dependencies": {
|
||||
|
@ -1,3 +1,5 @@
|
||||
import * as TypeMoq from 'typemoq';
|
||||
|
||||
import { DeviceType } from '../../../src/enums/deviceType';
|
||||
|
||||
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) {
|
||||
const platformUtilsService = new BrowserPlatformUtilsService(edge);
|
||||
return new WebCryptoFunctionService(window, platformUtilsService);
|
||||
const platformUtilsMock = TypeMoq.Mock.ofType<PlatformUtilsService>(PlatformUtilsServiceMock);
|
||||
platformUtilsMock.setup((x) => x.isEdge()).returns(() => edge);
|
||||
return new WebCryptoFunctionService(window, platformUtilsMock.object);
|
||||
}
|
||||
|
||||
function makeStaticByteArray(length: number) {
|
||||
@ -277,31 +280,6 @@ function makeStaticByteArray(length: number) {
|
||||
return arr;
|
||||
}
|
||||
|
||||
class BrowserPlatformUtilsService implements PlatformUtilsService {
|
||||
identityClientId: string;
|
||||
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;
|
||||
}
|
||||
class PlatformUtilsServiceMock extends PlatformUtilsService {
|
||||
isEdge = () => false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user