Skip to content

Commit

Permalink
Added Client.getExecution(switcher) (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
petruki authored May 11, 2024
1 parent 8997b0b commit 4dd26a8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,13 @@ export class Client {
return ExecutionLogger.getByKey(key);
}

/**
* Retrieve execution log from a switcher
*/
static getExecution(switcher: Switcher): ExecutionLogger {
return ExecutionLogger.getExecution(switcher.key, switcher.input);
}

/**
* Clear all results from the execution log
*/
Expand Down
12 changes: 11 additions & 1 deletion src/switcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class Switcher {
/**
* Checks API credentials and connectivity
*/
async prepare(key: string): Promise<void> {
async prepare(key?: string): Promise<void> {
this._validateArgs(key);

if (!Client.options.local || this._forceRemote) {
Expand Down Expand Up @@ -293,6 +293,16 @@ export class Switcher {
return this._delay == 0 || !ExecutionLogger.getExecution(this._key, this._input);
}

/**
* Return switcher key
*/
get key(): string {
return this._key;
}

/**
* Return switcher current strategy input
*/
get input(): string[][] | undefined {
return this._input;
}
Expand Down
17 changes: 17 additions & 0 deletions test/switcher-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@ describe('E2E test - Client local:', function () {
assertTrue(await switcher.isItOn('FF2FOR2020'));
});

it('should get execution from logger', async function () {
await switcher
.checkValue('Japan')
.checkNetwork('10.0.0.3')
.prepare('FF2FOR2020');

await switcher.isItOn('FF2FOR2020');
const log = Client.getExecution(switcher);

assertEquals(log.key, 'FF2FOR2020');
assertEquals(log.input, [
[ 'VALUE_VALIDATION', 'Japan' ],
[ 'NETWORK_VALIDATION', '10.0.0.3' ]]);
assertEquals(log.response.reason, 'Success');
assertEquals(log.response.result, true);
});

it('should be valid - isItOn - with detail', testSettings, async function () {
const response = await switcher.detail()
.checkValue('Japan')
Expand Down

0 comments on commit 4dd26a8

Please sign in to comment.