Skip to content

Commit b79fa18

Browse files
committed
refactored to use common helper
1 parent 5d986fb commit b79fa18

32 files changed

+475
-535
lines changed

packages/b2c-cli/test/commands/auth/token.test.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,21 @@
55
*/
66

77
import {expect} from 'chai';
8+
import {afterEach, beforeEach} from 'mocha';
89
import sinon from 'sinon';
9-
import {Config, ux} from '@oclif/core';
10+
import {ux} from '@oclif/core';
1011
import AuthToken from '../../../src/commands/auth/token.js';
11-
import {isolateConfig, restoreConfig} from '../../helpers/config-isolation.js';
12+
import {createIsolatedConfigHooks} from '../../helpers/test-setup.js';
1213

1314
describe('auth token', () => {
14-
let config: Config;
15+
const hooks = createIsolatedConfigHooks();
1516

16-
beforeEach(async () => {
17-
isolateConfig();
18-
config = await Config.load();
19-
});
17+
beforeEach(hooks.beforeEach);
2018

21-
afterEach(() => {
22-
sinon.restore();
23-
restoreConfig();
24-
});
19+
afterEach(hooks.afterEach);
2520

2621
function createCommand(): any {
27-
return new AuthToken([], config);
22+
return new AuthToken([], hooks.getConfig());
2823
}
2924

3025
it('returns structured JSON in JSON mode', async () => {

packages/b2c-cli/test/commands/code/activate.test.ts

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,21 @@
55
*/
66

77
import {expect} from 'chai';
8+
import {afterEach, beforeEach} from 'mocha';
89
import sinon from 'sinon';
9-
import {Config} from '@oclif/core';
1010
import CodeActivate from '../../../src/commands/code/activate.js';
11-
import {isolateConfig, restoreConfig} from '../../helpers/config-isolation.js';
12-
import {stubParse} from '../../helpers/stub-parse.js';
11+
import {createIsolatedConfigHooks, createTestCommand} from '../../helpers/test-setup.js';
1312

1413
describe('code activate', () => {
15-
let config: Config;
14+
const hooks = createIsolatedConfigHooks();
1615

17-
async function createCommand(flags: Record<string, unknown>, args: Record<string, unknown>) {
18-
const command: any = new CodeActivate([], config);
19-
stubParse(command, flags, args);
20-
await command.init();
21-
return command;
22-
}
16+
beforeEach(hooks.beforeEach);
2317

24-
beforeEach(async () => {
25-
isolateConfig();
26-
config = await Config.load();
27-
});
18+
afterEach(hooks.afterEach);
2819

29-
afterEach(() => {
30-
sinon.restore();
31-
restoreConfig();
32-
});
20+
async function createCommand(flags: Record<string, unknown>, args: Record<string, unknown>) {
21+
return createTestCommand(CodeActivate, hooks.getConfig(), flags, args);
22+
}
3323

3424
it('activates when --reload is not set', async () => {
3525
const command: any = await createCommand({}, {codeVersion: 'v1'});

packages/b2c-cli/test/commands/code/delete.test.ts

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,21 @@
55
*/
66

77
import {expect} from 'chai';
8+
import {afterEach, beforeEach} from 'mocha';
89
import sinon from 'sinon';
9-
import {Config} from '@oclif/core';
1010
import CodeDelete from '../../../src/commands/code/delete.js';
11-
import {isolateConfig, restoreConfig} from '../../helpers/config-isolation.js';
12-
import {stubParse} from '../../helpers/stub-parse.js';
11+
import {createIsolatedConfigHooks, createTestCommand} from '../../helpers/test-setup.js';
1312

1413
describe('code delete', () => {
15-
let config: Config;
14+
const hooks = createIsolatedConfigHooks();
1615

17-
async function createCommand(flags: Record<string, unknown>, args: Record<string, unknown>) {
18-
const command: any = new CodeDelete([], config);
19-
stubParse(command, flags, args);
20-
await command.init();
21-
return command;
22-
}
16+
beforeEach(hooks.beforeEach);
2317

24-
beforeEach(async () => {
25-
isolateConfig();
26-
config = await Config.load();
27-
});
18+
afterEach(hooks.afterEach);
2819

29-
afterEach(() => {
30-
sinon.restore();
31-
restoreConfig();
32-
});
20+
async function createCommand(flags: Record<string, unknown>, args: Record<string, unknown>) {
21+
return createTestCommand(CodeDelete, hooks.getConfig(), flags, args);
22+
}
3323

3424
it('deletes without prompting when --force is set', async () => {
3525
const command: any = await createCommand({force: true}, {codeVersion: 'v1'});

packages/b2c-cli/test/commands/code/deploy.test.ts

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,21 @@
55
*/
66

77
import {expect} from 'chai';
8+
import {afterEach, beforeEach} from 'mocha';
89
import sinon from 'sinon';
9-
import {Config} from '@oclif/core';
1010
import CodeDeploy from '../../../src/commands/code/deploy.js';
11-
import {isolateConfig, restoreConfig} from '../../helpers/config-isolation.js';
12-
import {stubParse} from '../../helpers/stub-parse.js';
11+
import {createIsolatedConfigHooks, createTestCommand} from '../../helpers/test-setup.js';
1312

1413
describe('code deploy', () => {
15-
let config: Config;
14+
const hooks = createIsolatedConfigHooks();
1615

17-
async function createCommand(flags: Record<string, unknown>, args: Record<string, unknown>) {
18-
const command: any = new CodeDeploy([], config);
19-
stubParse(command, flags, args);
20-
await command.init();
21-
return command;
22-
}
16+
beforeEach(hooks.beforeEach);
2317

24-
beforeEach(async () => {
25-
isolateConfig();
26-
config = await Config.load();
27-
});
18+
afterEach(hooks.afterEach);
2819

29-
afterEach(() => {
30-
sinon.restore();
31-
restoreConfig();
32-
});
20+
async function createCommand(flags: Record<string, unknown>, args: Record<string, unknown>) {
21+
return createTestCommand(CodeDeploy, hooks.getConfig(), flags, args);
22+
}
3323

3424
function stubCommon(command: any) {
3525
sinon.stub(command, 'requireWebDavCredentials').returns(void 0);

packages/b2c-cli/test/commands/code/list.test.ts

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,23 @@
44
* For full license text, see the license.txt file in the repo root or http://www.apache.org/licenses/LICENSE-2.0
55
*/
66

7-
import {ux, Config} from '@oclif/core';
7+
import {ux} from '@oclif/core';
88
import {expect} from 'chai';
9+
import {afterEach, beforeEach} from 'mocha';
910
import sinon from 'sinon';
1011
import CodeList from '../../../src/commands/code/list.js';
11-
import {isolateConfig, restoreConfig} from '../../helpers/config-isolation.js';
12-
import {stubParse} from '../../helpers/stub-parse.js';
12+
import {createIsolatedConfigHooks, createTestCommand} from '../../helpers/test-setup.js';
1313

1414
describe('code list', () => {
15-
let config: Config;
15+
const hooks = createIsolatedConfigHooks();
1616

17-
async function createCommand(flags: Record<string, unknown>) {
18-
const command: any = new CodeList([], config);
19-
stubParse(command, flags, {});
20-
await command.init();
21-
return command;
22-
}
17+
beforeEach(hooks.beforeEach);
2318

24-
beforeEach(async () => {
25-
isolateConfig();
26-
config = await Config.load();
27-
});
19+
afterEach(hooks.afterEach);
2820

29-
afterEach(() => {
30-
sinon.restore();
31-
restoreConfig();
32-
});
21+
async function createCommand(flags: Record<string, unknown>) {
22+
return createTestCommand(CodeList, hooks.getConfig(), flags, {});
23+
}
3324

3425
it('returns data in json mode', async () => {
3526
const command: any = await createCommand({json: true});

packages/b2c-cli/test/commands/code/watch.test.ts

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,21 @@
55
*/
66

77
import {expect} from 'chai';
8+
import {afterEach, beforeEach} from 'mocha';
89
import sinon from 'sinon';
9-
import {Config} from '@oclif/core';
1010
import CodeWatch from '../../../src/commands/code/watch.js';
11-
import {isolateConfig, restoreConfig} from '../../helpers/config-isolation.js';
12-
import {stubParse} from '../../helpers/stub-parse.js';
11+
import {createIsolatedConfigHooks, createTestCommand} from '../../helpers/test-setup.js';
1312

1413
describe('code watch', () => {
15-
let config: Config;
14+
const hooks = createIsolatedConfigHooks();
1615

17-
async function createCommand(flags: Record<string, unknown>, args: Record<string, unknown>) {
18-
const command: any = new CodeWatch([], config);
19-
stubParse(command, flags, args);
20-
await command.init();
21-
return command;
22-
}
16+
beforeEach(hooks.beforeEach);
2317

24-
beforeEach(async () => {
25-
isolateConfig();
26-
config = await Config.load();
27-
});
18+
afterEach(hooks.afterEach);
2819

29-
afterEach(() => {
30-
sinon.restore();
31-
restoreConfig();
32-
});
20+
async function createCommand(flags: Record<string, unknown>, args: Record<string, unknown>) {
21+
return createTestCommand(CodeWatch, hooks.getConfig(), flags, args);
22+
}
3323

3424
it('stops watcher on SIGINT', async () => {
3525
const command: any = await createCommand({}, {cartridgePath: '.'});

packages/b2c-cli/test/commands/docs/download.test.ts

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,21 @@
55
*/
66

77
import {expect} from 'chai';
8+
import {afterEach, beforeEach} from 'mocha';
89
import sinon from 'sinon';
9-
import {Config} from '@oclif/core';
1010
import DocsDownload from '../../../src/commands/docs/download.js';
11-
import {isolateConfig, restoreConfig} from '../../helpers/config-isolation.js';
12-
import {stubParse} from '../../helpers/stub-parse.js';
11+
import {createIsolatedConfigHooks, createTestCommand} from '../../helpers/test-setup.js';
1312

1413
describe('docs download', () => {
15-
let config: Config;
14+
const hooks = createIsolatedConfigHooks();
1615

17-
async function createCommand(flags: Record<string, unknown>, args: Record<string, unknown>) {
18-
const command: any = new DocsDownload([], config);
19-
stubParse(command, flags, args);
20-
await command.init();
21-
return command;
22-
}
16+
beforeEach(hooks.beforeEach);
2317

24-
beforeEach(async () => {
25-
isolateConfig();
26-
config = await Config.load();
27-
});
18+
afterEach(hooks.afterEach);
2819

29-
afterEach(() => {
30-
sinon.restore();
31-
restoreConfig();
32-
});
20+
async function createCommand(flags: Record<string, unknown>, args: Record<string, unknown>) {
21+
return createTestCommand(DocsDownload, hooks.getConfig(), flags, args);
22+
}
3323

3424
it('calls downloadDocs with outputDir and keepArchive', async () => {
3525
const command: any = await createCommand({'keep-archive': true}, {output: './docs'});

packages/b2c-cli/test/commands/docs/read.test.ts

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,21 @@
55
*/
66

77
import {expect} from 'chai';
8+
import {afterEach, beforeEach} from 'mocha';
89
import sinon from 'sinon';
9-
import {Config} from '@oclif/core';
1010
import DocsRead from '../../../src/commands/docs/read.js';
11-
import {isolateConfig, restoreConfig} from '../../helpers/config-isolation.js';
12-
import {stubParse} from '../../helpers/stub-parse.js';
11+
import {createIsolatedConfigHooks, createTestCommand} from '../../helpers/test-setup.js';
1312

1413
describe('docs read', () => {
15-
let config: Config;
14+
const hooks = createIsolatedConfigHooks();
1615

17-
async function createCommand(flags: Record<string, unknown>, args: Record<string, unknown>) {
18-
const command: any = new DocsRead([], config);
19-
stubParse(command, flags, args);
20-
await command.init();
21-
return command;
22-
}
16+
beforeEach(hooks.beforeEach);
2317

24-
beforeEach(async () => {
25-
isolateConfig();
26-
config = await Config.load();
27-
});
18+
afterEach(hooks.afterEach);
2819

29-
afterEach(() => {
30-
sinon.restore();
31-
restoreConfig();
32-
});
20+
async function createCommand(flags: Record<string, unknown>, args: Record<string, unknown>) {
21+
return createTestCommand(DocsRead, hooks.getConfig(), flags, args);
22+
}
3323

3424
it('errors when no match is found', async () => {
3525
const command: any = await createCommand({}, {query: 'Nope'});

packages/b2c-cli/test/commands/docs/schema.test.ts

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,21 @@
55
*/
66

77
import {expect} from 'chai';
8+
import {afterEach, beforeEach} from 'mocha';
89
import sinon from 'sinon';
9-
import {Config} from '@oclif/core';
1010
import DocsSchema from '../../../src/commands/docs/schema.js';
11-
import {isolateConfig, restoreConfig} from '../../helpers/config-isolation.js';
12-
import {stubParse} from '../../helpers/stub-parse.js';
11+
import {createIsolatedConfigHooks, createTestCommand} from '../../helpers/test-setup.js';
1312

1413
describe('docs schema', () => {
15-
let config: Config;
14+
const hooks = createIsolatedConfigHooks();
1615

17-
async function createCommand(flags: Record<string, unknown>, args: Record<string, unknown>) {
18-
const command: any = new DocsSchema([], config);
19-
stubParse(command, flags, args);
20-
await command.init();
21-
return command;
22-
}
16+
beforeEach(hooks.beforeEach);
2317

24-
beforeEach(async () => {
25-
isolateConfig();
26-
config = await Config.load();
27-
});
18+
afterEach(hooks.afterEach);
2819

29-
afterEach(() => {
30-
sinon.restore();
31-
restoreConfig();
32-
});
20+
async function createCommand(flags: Record<string, unknown>, args: Record<string, unknown>) {
21+
return createTestCommand(DocsSchema, hooks.getConfig(), flags, args);
22+
}
3323

3424
it('lists schemas in json mode', async () => {
3525
const command: any = await createCommand({list: true, json: true}, {});

packages/b2c-cli/test/commands/docs/search.test.ts

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,23 @@
44
* For full license text, see the license.txt file in the repo root or http://www.apache.org/licenses/LICENSE-2.0
55
*/
66

7-
import {ux, Config} from '@oclif/core';
7+
import {ux} from '@oclif/core';
88
import {expect} from 'chai';
9+
import {afterEach, beforeEach} from 'mocha';
910
import sinon from 'sinon';
1011
import DocsSearch from '../../../src/commands/docs/search.js';
11-
import {isolateConfig, restoreConfig} from '../../helpers/config-isolation.js';
12-
import {stubParse} from '../../helpers/stub-parse.js';
12+
import {createIsolatedConfigHooks, createTestCommand} from '../../helpers/test-setup.js';
1313

1414
describe('docs search', () => {
15-
let config: Config;
15+
const hooks = createIsolatedConfigHooks();
1616

17-
async function createCommand(flags: Record<string, unknown>, args: Record<string, unknown>) {
18-
const command: any = new DocsSearch([], config);
19-
stubParse(command, flags, args);
20-
await command.init();
21-
return command;
22-
}
17+
beforeEach(hooks.beforeEach);
2318

24-
beforeEach(async () => {
25-
isolateConfig();
26-
config = await Config.load();
27-
});
19+
afterEach(hooks.afterEach);
2820

29-
afterEach(() => {
30-
sinon.restore();
31-
restoreConfig();
32-
});
21+
async function createCommand(flags: Record<string, unknown>, args: Record<string, unknown>) {
22+
return createTestCommand(DocsSearch, hooks.getConfig(), flags, args);
23+
}
3324

3425
it('errors when query is missing in search mode', async () => {
3526
const command: any = await createCommand({}, {});

0 commit comments

Comments
 (0)