Files
privacy.sexy/tests/unit/stubs/FunctionDataStub.ts
undergroundwires 60c80611ea add module alias '@tests/'
Alias would remove unnecessary repetitions and less relative paths make changes easier when moving around files. This commit cleans also up some relative paths ('../../../') by using the alias and orders imports. It updates both path alias in tsconfig and module alias in Vue CLI's bundler (vuejs/vue-cli#2398).
2021-04-15 18:34:40 +02:00

55 lines
1.5 KiB
TypeScript

import { FunctionData, ScriptFunctionCallData } from 'js-yaml-loader!@/*';
export class FunctionDataStub implements FunctionData {
public static createWithCode() {
return new FunctionDataStub()
.withCode('stub-code')
.withRevertCode('stub-revert-code');
}
public static createWithCall(call?: ScriptFunctionCallData) {
let instance = new FunctionDataStub();
if (call) {
instance = instance.withCall(call);
} else {
instance = instance.withMockCall();
}
return instance;
}
public static createWithoutCallOrCodes() {
return new FunctionDataStub();
}
public name = 'function data stub';
public code: string;
public revertCode: string;
public parameters?: readonly string[];
public call?: ScriptFunctionCallData;
private constructor() { }
public withName(name: string) {
this.name = name;
return this;
}
public withParameters(...parameters: string[]) {
this.parameters = parameters;
return this;
}
public withCode(code: string) {
this.code = code;
return this;
}
public withRevertCode(revertCode: string) {
this.revertCode = revertCode;
return this;
}
public withCall(call: ScriptFunctionCallData) {
this.call = call;
return this;
}
public withMockCall() {
this.call = { function: 'func' };
return this;
}
}