Best JavaScript code snippet using stryker-parent
LocalStore.TEST.ts
Source:LocalStore.TEST.ts
1/* eslint-disable jest/no-commented-out-tests */2// TODO :- We will come back to this after the wild wild west phase is over :) Yee haww.3// import Store from 'electron-store';4// import * as localStore from './LocalStore';5// const setup = () => {6// // Mocks7// const mockStoreGet = jest.fn((key: string) => {8// return key;9// });10// const mockStoreSet = jest.fn();11// const mockStore = {12// get: mockStoreGet,13// set: mockStoreSet,14// };15// // @ts-ignore mock16// localStore.setStore(mockStore);17// return {18// localStore,19// mockStoreGet,20// mockStoreSet,21// };22// };23// // TODO: Fix These Tests!!!24// describe('LocalStore', () => {25// // describe('export', () => {26// // test('default export the LocalStore class', () => {27// // expect(typeof localStore).toMatch('function');28// // expect(LocalStore.name).toMatch('LocalStore');29// // });30// // });31// describe('constructor', () => {32// setup();33// // test('initalize the electron-store object as this.store by default', () => {34// // setup();35// // expect(localStore.store).toBeInstanceOf(Store);36// // });37// // test('set this.store if given store argument', () => {38// // const { MockLocalStoreInstance, mockStore } = setup();39// // expect(MockLocalStoreInstance.store).toBe(mockStore);40// // });41// // test('set this.schema', () => {42// // const { LocalStoreInstance } = setup();43// // expect(LocalStoreInstance.schema).toBe(schema);44// // });45// });46// describe('functions', () => {47// describe('.getEncryptedEntropy', () => {48// test('return store.get for encryptedEntropy', () => {49// const { localStore, mockStoreGet } = setup();50// expect(localStore.getEncryptedEntropy()).toBe(localStore.schemaKeys.ENCRYPTED_ENTROPY);51// expect(mockStoreGet).toHaveBeenCalledWith(localStore.schemaKeys.ENCRYPTED_ENTROPY);52// });53// });54// describe('.getFullServiceLedgerDbPath', () => {55// test('return store.get for ledgerDbPath', () => {56// const { MockLocalStoreInstance, mockStoreGet } = setup();57// expect(MockLocalStoreInstance.getFullServiceLedgerDbPath()).toBe(58// schemaKeys.FULL_SERVICE_LEDGER_DB_PATH59// );60// expect(mockStoreGet).toHaveBeenCalledWith(schemaKeys.FULL_SERVICE_LEDGER_DB_PATH);61// });62// });63// describe('.getFullServiceDbPath', () => {64// test('return store.get for fullServiceDbPath', () => {65// const { MockLocalStoreInstance, mockStoreGet } = setup();66// expect(MockLocalStoreInstance.getFullServiceDbPath()).toBe(schemaKeys.FULL_SERVICE_DB_PATH);67// expect(mockStoreGet).toHaveBeenCalledWith(schemaKeys.FULL_SERVICE_DB_PATH);68// });69// });70// describe('.getGiftCodes', () => {71// test('return store.get for giftCodes', () => {72// const { MockLocalStoreInstance, mockStoreGet } = setup();73// describe('.getGiftCodes', () => {74// test('return store.get for giftCodes', () => {75// const { MockLocalStoreInstance, mockStoreGet } = setup();76// expect(MockLocalStoreInstance.getGiftCodes()).toBe(localStore.schemaKeys.GIFT_CODES);77// expect(mockStoreGet).toHaveBeenCalledWith(localStore.schemaKeys.GIFT_CODES);78// });79// });80// describe('.setGiftCodes', () => {81// test('return store.set for giftCodes', () => {82// const { MockLocalStoreInstance, mockStoreSet } = setup();83// const fakeGiftCodes = ['fakeGiftCodes'];84// describe('.getLeaveFullServiceRunning', () => {85// test('return store.get for leaveFullServiceRunning', () => {86// const { MockLocalStoreInstance, mockStoreGet } = setup();87// expect(MockLocalStoreInstance.getLeaveFullServiceRunning()).toBe(88// schemaKeys.LEAVE_FULL_SERVICE_RUNNING89// );90// expect(mockStoreGet).toHaveBeenCalledWith(schemaKeys.LEAVE_FULL_SERVICE_RUNNING);91// });92// });93// describe('.setLeaveFullServiceRunning', () => {94// test('return store.set for leaveFullServiceRunning', () => {95// const { MockLocalStoreInstance, mockStoreSet } = setup();96// const fakeLeaveFullServiceRunning = false;97// MockLocalStoreInstance.setLeaveFullServiceRunning(fakeLeaveFullServiceRunning);98// expect(mockStoreSet).toHaveBeenCalledWith(99// schemaKeys.LEAVE_FULL_SERVICE_RUNNING,100// fakeLeaveFullServiceRunning101// );102// });103// });104// describe('.getFullServiceLedgerDbPath', () => {105// test('return store.get for ledgerDbPath', () => {106// const { MockLocalStoreInstance, mockStoreGet } = setup();107// expect(MockLocalStoreInstance.getFullServiceLedgerDbPath()).toBe(108// schemaKeys.FULL_SERVICE_LEDGER_DB_PATH109// );110// expect(mockStoreGet).toHaveBeenCalledWith(schemaKeys.FULL_SERVICE_LEDGER_DB_PATH);111// });112// });113// describe('.getFullServiceDbPath', () => {114// test('return store.get for fullServiceDbPath', () => {115// const { MockLocalStoreInstance, mockStoreGet } = setup();116// expect(MockLocalStoreInstance.getFullServiceDbPath()).toBe(schemaKeys.FULL_SERVICE_DB_PATH);117// expect(mockStoreGet).toHaveBeenCalledWith(schemaKeys.FULL_SERVICE_DB_PATH);118// });119// });120// describe('.setLedgerDbPath', () => {121// test('return store.set for setLedgerDbPath', () => {122// const { MockLocalStoreInstance, mockStoreSet } = setup();123// const fakeFullServiceLedgerDbPath = '/fake/full-service/ledger/';124// const fakeFullServiceDbPath = '/fake/path/full-servide/db';125// MockLocalStoreInstance.setDbPaths(126// fakeFullServiceLedgerDbPath,127// fakeFullServiceDbPath,128// fakeFullServiceLedgerDbPath,129// fakeFullServiceDbPath130// );131// expect(mockStoreSet).toHaveBeenCalledWith({132// [schemaKeys.FULL_SERVICE_LEDGER_DB_PATH]: fakeFullServiceLedgerDbPath,133// [schemaKeys.FULL_SERVICE_DB_PATH]: fakeFullServiceDbPath,134// [schemaKeys.FULL_SERVICE_LEDGER_DB_PATH]: fakeFullServiceLedgerDbPath,135// [schemaKeys.FULL_SERVICE_DB_PATH]: fakeFullServiceDbPath,136// });137// });138// });139// MockLocalStoreInstance.setMobilecoindDbPath(fakeMobilecoindDbPath);140// expect(mockStoreSet).toHaveBeenCalledWith(141// schemaKeys.MOBILECOIND_DB_PATH,142// fakeMobilecoindDbPath143// );144// });145// });146// describe('.getName', () => {147// test('return store.get for Name', () => {148// const { MockLocalStoreInstance, mockStoreGet } = setup();149// expect(MockLocalStoreInstance.getName()).toBe(schemaKeys.NAME);150// expect(mockStoreGet).toHaveBeenCalledWith(schemaKeys.NAME);151// });152// });153// describe('.setName', () => {154// test('return store.set for Name', () => {155// const { MockLocalStoreInstance, mockStoreSet } = setup();156// const fakeName = 'Tom Fakery';157// MockLocalStoreInstance.setName(fakeName);158// expect(mockStoreSet).toHaveBeenCalledWith(schemaKeys.NAME, fakeName);159// });160// });161// describe('.getSalt', () => {162// test('return store.get for Salt', () => {163// const { MockLocalStoreInstance, mockStoreGet } = setup();164// expect(MockLocalStoreInstance.getSalt()).toBe(schemaKeys.SALT);165// expect(mockStoreGet).toHaveBeenCalledWith(schemaKeys.SALT);166// });167// });168// describe('.setSalt', () => {169// test('return store.set for Salt', () => {170// const { MockLocalStoreInstance, mockStoreSet } = setup();171// const fakeSalt = 'salt/fakery';172// MockLocalStoreInstance.setSalt(fakeSalt);173// expect(mockStoreSet).toHaveBeenCalledWith(schemaKeys.SALT, fakeSalt);174// });175// });176// });...
LocalStore.ts
Source:LocalStore.ts
1import * as fs from 'fs';2import Store from 'electron-store';3import { SjclCipherEncrypted } from 'sjcl';4import type { StringUInt64 } from '../types/SpecialStrings.d';5interface LocalStoreSchema {6 [key: string]: { type: 'string' | 'array' | 'boolean' };7}8const STORE_NAME = 'mobilecoin_config';9export const schemaKeys = {10 ENCRYPTED_CONTACTS: 'encryptedContacts',11 ENCRYPTED_PASSPHRASE: 'encryptedPassphrase',12 ENCRYPTED_PIN: 'encryptedPin',13 FULL_SERVICE_BINARIES_PATH: 'fullServiceBinariesPath',14 FULL_SERVICE_DB_EXISTS: 'fullServiceDbExists',15 FULL_SERVICE_DB_PATH: 'fullServiceDbPath',16 FULL_SERVICE_LEDGER_DB_PATH: 'fullServiceLedgerDbPath',17 GIFT_CODES: 'giftCodes',18 LEAVE_FULL_SERVICE_RUNNING: 'leaveFullServiceRunning',19 LEDGER_DB_PATH: 'ledgerDbPath',20 NAME: 'name',21 OFFLINE_START: 'offlineStart',22 PIN_THRESHOLD_PMOB: 'pinThresholdPmob',23 SALT: 'salt',24 THEME: 'theme',25};26export const schema: LocalStoreSchema = {27 [schemaKeys.ENCRYPTED_CONTACTS]: { type: 'string' },28 [schemaKeys.ENCRYPTED_PASSPHRASE]: { type: 'string' },29 [schemaKeys.ENCRYPTED_PIN]: { type: 'string' },30 [schemaKeys.FULL_SERVICE_BINARIES_PATH]: { type: 'string' },31 [schemaKeys.FULL_SERVICE_DB_EXISTS]: { type: 'string' },32 [schemaKeys.FULL_SERVICE_DB_PATH]: { type: 'string' },33 [schemaKeys.FULL_SERVICE_LEDGER_DB_PATH]: { type: 'string' },34 [schemaKeys.GIFT_CODES]: { type: 'array' },35 [schemaKeys.LEAVE_FULL_SERVICE_RUNNING]: { type: 'boolean' },36 [schemaKeys.LEDGER_DB_PATH]: { type: 'string' },37 [schemaKeys.NAME]: { type: 'string' },38 [schemaKeys.OFFLINE_START]: { type: 'boolean' },39 [schemaKeys.PIN_THRESHOLD_PMOB]: { type: 'string' },40 [schemaKeys.SALT]: { type: 'string' },41 [schemaKeys.THEME]: { type: 'string' },42};43let store = new Store({ name: STORE_NAME, schema });44export const setStore = (newStore: Store): void => {45 store = newStore;46};47export const setOfflineStart = (startOffline: boolean): void =>48 store.set(schemaKeys.OFFLINE_START, startOffline);49export const getOfflineStart = (): boolean => store.get(schemaKeys.OFFLINE_START) as boolean;50export const getEncryptedContacts = (): SjclCipherEncrypted =>51 store.get(schemaKeys.ENCRYPTED_CONTACTS) as SjclCipherEncrypted;52export const setEncryptedContacts = (encryptedContacts: SjclCipherEncrypted): void =>53 store.set(schemaKeys.ENCRYPTED_CONTACTS, encryptedContacts);54export const deleteEncryptedContacts = (): void => store.delete(schemaKeys.ENCRYPTED_CONTACTS);55export const getGiftCodes = (): Array<string> => store.get(schemaKeys.GIFT_CODES) as Array<string>;56export const setGiftCodes = (giftCodes: Array<string>): void =>57 store.set(schemaKeys.GIFT_CODES, giftCodes);58export const getEncryptedPin = (): SjclCipherEncrypted | undefined =>59 store.get(schemaKeys.ENCRYPTED_PIN) as SjclCipherEncrypted | undefined;60export const setEncryptedPin = (encryptedPin: SjclCipherEncrypted): void =>61 store.set(schemaKeys.ENCRYPTED_PIN, encryptedPin);62export const deleteEncryptedPin = (): void => store.delete(schemaKeys.ENCRYPTED_PIN);63export const getLeaveFullServiceRunning = (): boolean =>64 store.get(schemaKeys.LEAVE_FULL_SERVICE_RUNNING) as boolean;65export const setLeaveFullServiceRunning = (leaveFullServiceRunning: boolean): void =>66 store.set(schemaKeys.LEAVE_FULL_SERVICE_RUNNING, leaveFullServiceRunning);67export const getPinThresholdPmob = (): StringUInt64 =>68 store.get(schemaKeys.PIN_THRESHOLD_PMOB) as StringUInt64;69export const setPinThresholdPmob = (pinThresholdPmob: StringUInt64): void =>70 store.set(schemaKeys.PIN_THRESHOLD_PMOB, pinThresholdPmob);71export const deletePinThresholdPmob = (): void => store.delete(schemaKeys.PIN_THRESHOLD_PMOB);72// TODO - add type guards to app73// https://www.typescriptlang.org/docs/handbook/advanced-types.html#typeof-type-guards74export const getLedgerDbPath = (): string => {75 const ledgerDbPath = store.get(schemaKeys.LEDGER_DB_PATH);76 return typeof ledgerDbPath === 'string' ? ledgerDbPath : '';77};78export const getTheme = (): string => {79 const theme = store.get(schemaKeys.THEME);80 return typeof theme === 'string' ? theme : 'system';81};82export const getEncryptedPassphrase = (): SjclCipherEncrypted | undefined =>83 store.get(schemaKeys.ENCRYPTED_PASSPHRASE) as SjclCipherEncrypted | undefined;84export const setEncryptedPassphrase = (encryptedPassphrase: SjclCipherEncrypted): void =>85 store.set({86 [schemaKeys.ENCRYPTED_PASSPHRASE]: encryptedPassphrase,87 });88export const deleteEncryptedPassphrase = (): void => store.delete(schemaKeys.ENCRYPTED_PASSPHRASE);89export const getFullServiceDbPath = (): string => {90 const fullServiceDbPath = store.get(schemaKeys.FULL_SERVICE_DB_PATH);91 return typeof fullServiceDbPath === 'string' ? fullServiceDbPath : '';92};93export const getWalletDbExists = (): boolean => {94 const path = [getFullServiceDbPath(), 'wallet.db'].join('/');95 return fs.existsSync(path);96};97export const getFullServiceLedgerDbPath = (): string =>98 store.get(schemaKeys.LEDGER_DB_PATH) as string;99export const getFullServiceBinariesPath = (): string =>100 store.get(schemaKeys.FULL_SERVICE_BINARIES_PATH) as string;101export const setFullServiceBinariesPath = (name: string): void =>102 store.set(schemaKeys.FULL_SERVICE_BINARIES_PATH, name);103export const setLedgerDbPath = (name: string): void => store.set(schemaKeys.LEDGER_DB_PATH, name);104export const setFullServiceDbPath = (name: string): void =>105 store.set(schemaKeys.FULL_SERVICE_DB_PATH, name);106export const getName = (): string => store.get(schemaKeys.NAME) as string;107export const setName = (name: string | null): void => store.set(schemaKeys.NAME, name);108export const getSalt = (): string => store.get(schemaKeys.SALT) as string;109export const setSalt = (salt: string): void => store.set(schemaKeys.SALT, salt);110export const setTheme = (theme: 'system' | 'light' | 'dark'): void =>...
map-schema-keys-to-data-keys.test.js
Source:map-schema-keys-to-data-keys.test.js
1'use strict';2const test = require('tape');3const moduleName = 'lib/util/map-schema-keys-to-data-keys';4const self = require(`../../../${moduleName}`);5test(`${moduleName} > schema matches data w/o case insensitivity`, t => {6 const dataKeys = ['keyOne', 'keyTwo'];7 const schemaKeys = [...dataKeys];8 const { schemaKeysToDataKeys, restDataKeys } = self({ dataKeys, schemaKeys });9 t.deepEqual(Array.from(schemaKeysToDataKeys.keys()), [...schemaKeys],10 'the keys map should include all schema keys');11 t.deepEqual(Array.from(schemaKeysToDataKeys.values()), [...dataKeys],12 'schema keys should map to factual dataKeys');13 t.equal(restDataKeys.length, 0, 'should return empty collection of rest keys');14 t.end();15});16test(`${moduleName} > schema matches data with case insensitivity`, t => {17 const dataKeys = ['keyOne', 'keyTwo'];18 const schemaKeys = [...dataKeys];19 const { schemaKeysToDataKeys, restDataKeys } =20 self({ dataKeys, schemaKeys, isCaseInsensitive: true });21 t.deepEqual(Array.from(schemaKeysToDataKeys.keys()), [...schemaKeys],22 'the keys map should include all schema keys');23 t.deepEqual(Array.from(schemaKeysToDataKeys.values()), [...dataKeys],24 'schema keys should map to factual dataKeys');25 t.equal(restDataKeys.length, 0, 'should return empty collection of rest keys');26 t.end();27});28test(`${moduleName} > there are data keys not covered by schema`, t => {29 const schemaKeys = ['keyOne', 'keyTwo'];30 const restKeys = ['keyThree', 'keyFour'];31 const dataKeys = [...schemaKeys, ...restKeys];32 const { restDataKeys } = self({ dataKeys, schemaKeys });33 t.deepEqual(restDataKeys, restKeys,34 'should return correct collection of keys not covered by schema');35 t.end();36});37test(`${moduleName} > the target key is only descoverable with case insensitivity`, t => {38 const restKeys = ['keyThree', 'keyFour'];39 const mappableDataKeys = ['keyOne', 'KeyTWO'];40 const dataKeys = [...mappableDataKeys, ...restKeys];41 const schemaKeys = ['keyOne', 'keyTwo'];42 const { schemaKeysToDataKeys, restDataKeys } =43 self({ dataKeys, schemaKeys, isCaseInsensitive: true });44 t.deepEqual(Array.from(schemaKeysToDataKeys.keys()), [...schemaKeys],45 'the keys map should include all schema keys');46 t.deepEqual(Array.from(schemaKeysToDataKeys.values()), [...mappableDataKeys],47 'schema keys should map to factual dataKeys');48 t.deepEqual(restDataKeys, restKeys,49 'should return correct collection of keys not covered by schema');50 t.end();51});52test(`${moduleName} > there are two similar data keys and case insensitivity is applied`, t => {53 const dataKeys = ['KeyOne', 'keyONE'];54 const schemaKeys = ['keyOne'];55 const { schemaKeysToDataKeys, restDataKeys } =56 self({ dataKeys, schemaKeys, isCaseInsensitive: true });57 t.equal(schemaKeysToDataKeys.get('keyOne'), 'keyONE',58 'schema key should reference the last data key entry');59 t.equal(restDataKeys.length, 0,60 'should not include the first entry to the rest data keys collection');61 t.end();62});63test(`${moduleName} > there are two similar data keys and case insensitivity is not applied`, t => {64 const dataKeys = ['KeyOne', 'keyONE'];65 const schemaKeys = ['keyOne'];66 const { schemaKeysToDataKeys, restDataKeys } =67 self({ dataKeys, schemaKeys, isCaseInsensitive: false });68 t.equal(schemaKeysToDataKeys.get('keyOne'), null,69 'schema key should not reference any data key');70 t.deepEqual(restDataKeys, dataKeys,71 'should include all not matched keys to the rest data keys collection');72 t.end();73});74test(`${moduleName} > schema has a key that data does not have`, t => {75 const dataKeys = [];76 const schemaKeys = ['keyOne'];77 const { schemaKeysToDataKeys } =78 self({ dataKeys, schemaKeys, isCaseInsensitive: false });79 t.equal(schemaKeysToDataKeys.get('keyOne'), null,80 'schema key should not reference any data key');81 t.end();...
Using AI Code Generation
1var schemaKeys = require('stryker-parent').schemaKeys;2var schemaKeys = require('stryker-parent').schemaKeys;3var schemaKeys = require('stryker-parent').schemaKeys;4var schemaKeys = require('stryker-parent').schemaKeys;5var schemaKeys = require('stryker-parent').schemaKeys;6var schemaKeys = require('stryker-parent').schemaKeys;7var schemaKeys = require('stryker-parent').schemaKeys;8var schemaKeys = require('stryker-parent').schemaKeys;9var schemaKeys = require('stryker-parent').schemaKeys;10var schemaKeys = require('stryker-parent').schemaKeys;11var schemaKeys = require('stryker-parent').schemaKeys;12var schemaKeys = require('stryker-parent').schemaKeys;13var schemaKeys = require('stryker-parent').schemaKeys;14var schemaKeys = require('stryker-parent').schemaKeys;15var schemaKeys = require('stryker-parent').schemaKeys;
Using AI Code Generation
1const schemaKeys = require('stryker-parent').schemaKeys;2const schema = require('./schema.json');3const keys = schemaKeys(schema);4console.log(keys);5{6 "definitions": {7 "logLevel": {8 }9 },10 "properties": {11 "name": {12 },13 "description": {14 },15 "files": {16 "items": {17 }18 },19 "testRunner": {20 },21 "mutator": {22 },23 "reporters": {24 "items": {25 }26 },27 "coverageAnalysis": {28 },29 "transpilers": {30 "items": {31 }32 },33 "testFramework": {34 },35 "maxConcurrentTestRunners": {36 },37 "thresholds": {38 "properties": {39 "high": {40 },41 "low": {
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!