Skip to content

Commit 5a96df9

Browse files
netrajpatelclaude
andcommitted
test(external-migrate): convert merged create-stack.test.ts from vitest to mocha [DX-9770]
The v2-dev backmerge (PR #304) added create-stack.test.ts written in vitest, but this branch converted external-migrate to mocha and removed the vitest dependency, so the file failed to compile ('Cannot find module vitest'). Rewrote its 6 scheduleEntryAction api_version:3.2 header tests using mocha/chai/sinon (stub axios.post + configHandler + authHandler), preserving PR #304's coverage. Refreshed the .talismanrc checksum for the rewritten file. external-migrate: 48 passing. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NbgqgVDTDmh6c9LwDtMEf9
1 parent 9e73968 commit 5a96df9

2 files changed

Lines changed: 34 additions & 39 deletions

File tree

.talismanrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fileignoreconfig:
3434
- filename: packages/contentstack-external-migrate/src/lib/create-stack.ts
3535
checksum: 68a9510db6f2746ac5006c091d276c1ba619a9e15c76a3edae3967e4f9c2dd4e
3636
- filename: packages/contentstack-external-migrate/test/lib/create-stack.test.ts
37-
checksum: 45af4e45e4baadf7e418a11a46a6243b8ffabafdbf32d0269d89c5d3db837a13
37+
checksum: 2dcbc359ee275e59e0536f3c325416eac8c43eb341b04da0d3757f5b5e556d9c
3838
- filename: CHANGELOG.md
3939
checksum: 88c7e1dee308fa4ae25e7815ead0842b1aac7ed669b02859cc8b25cba879595d
4040
- filename: packages/contentstack-bulk-operations/test/unit/services/taxonomy-service.test.ts
Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,9 @@
1-
import { beforeEach, describe, expect, it, vi } from 'vitest';
1+
import { expect } from 'chai';
2+
import sinon from 'sinon';
3+
import axios from 'axios';
4+
import { configHandler, authHandler } from '@contentstack/cli-utilities';
25
import { scheduleEntryAction } from '../../src/lib/create-stack';
36

4-
const { mockPost } = vi.hoisted(() => ({ mockPost: vi.fn() }));
5-
6-
vi.mock('axios', () => ({ default: { post: mockPost } }));
7-
8-
vi.mock('@contentstack/cli-utilities', () => ({
9-
configHandler: {
10-
get: vi.fn().mockImplementation((key: string) => {
11-
if (key === 'authorisationType') return 'BASIC';
12-
if (key === 'authtoken') return 'test-authtoken';
13-
if (key === 'region') return 'NA';
14-
return undefined;
15-
}),
16-
},
17-
authHandler: {
18-
checkExpiryAndRefresh: vi.fn().mockResolvedValue(undefined),
19-
},
20-
}));
21-
227
describe('scheduleEntryAction', () => {
238
const API_KEY = 'blt-test-api-key';
249
const ENTRY_OPTS = {
@@ -30,26 +15,36 @@ describe('scheduleEntryAction', () => {
3015
scheduledAt: '2026-08-01T10:00:00.000Z',
3116
};
3217

18+
let postStub: sinon.SinonStub;
19+
3320
beforeEach(() => {
34-
mockPost.mockReset();
35-
mockPost.mockResolvedValue({ data: {} });
21+
postStub = sinon.stub(axios, 'post').resolves({ data: {} } as any);
22+
sinon.stub(configHandler, 'get').callsFake((key: string) => {
23+
if (key === 'authorisationType') return 'BASIC';
24+
if (key === 'authtoken') return 'test-authtoken';
25+
if (key === 'region') return 'NA';
26+
return undefined;
27+
});
28+
sinon.stub(authHandler, 'checkExpiryAndRefresh').resolves(undefined);
3629
});
3730

31+
afterEach(() => sinon.restore());
32+
3833
it('sends api_version: 3.2 header on entry publish', async () => {
3934
await scheduleEntryAction(API_KEY, ENTRY_OPTS);
4035

41-
expect(mockPost).toHaveBeenCalledOnce();
42-
const [url, , { headers }] = mockPost.mock.calls[0];
43-
expect(url).toContain('/v3/content_types/blog/entries/entry123/publish');
44-
expect(headers).toMatchObject({ api_version: '3.2' });
36+
expect(postStub.calledOnce).to.be.true;
37+
const [url, , { headers }] = postStub.firstCall.args;
38+
expect(url).to.contain('/v3/content_types/blog/entries/entry123/publish');
39+
expect(headers).to.include({ api_version: '3.2' });
4540
});
4641

4742
it('sends api_version: 3.2 header on entry unpublish', async () => {
4843
await scheduleEntryAction(API_KEY, { ...ENTRY_OPTS, action: 'unpublish' });
4944

50-
const [url, , { headers }] = mockPost.mock.calls[0];
51-
expect(url).toContain('/v3/content_types/blog/entries/entry123/unpublish');
52-
expect(headers).toMatchObject({ api_version: '3.2' });
45+
const [url, , { headers }] = postStub.firstCall.args;
46+
expect(url).to.contain('/v3/content_types/blog/entries/entry123/unpublish');
47+
expect(headers).to.include({ api_version: '3.2' });
5348
});
5449

5550
it('sends api_version: 3.2 header on asset publish (sys_assets)', async () => {
@@ -59,9 +54,9 @@ describe('scheduleEntryAction', () => {
5954
entryUid: 'asset456',
6055
});
6156

62-
const [url, , { headers }] = mockPost.mock.calls[0];
63-
expect(url).toContain('/v3/assets/asset456/publish');
64-
expect(headers).toMatchObject({ api_version: '3.2' });
57+
const [url, , { headers }] = postStub.firstCall.args;
58+
expect(url).to.contain('/v3/assets/asset456/publish');
59+
expect(headers).to.include({ api_version: '3.2' });
6560
});
6661

6762
it('sends api_version: 3.2 header on asset unpublish (sys_assets)', async () => {
@@ -72,22 +67,22 @@ describe('scheduleEntryAction', () => {
7267
action: 'unpublish',
7368
});
7469

75-
const [url, , { headers }] = mockPost.mock.calls[0];
76-
expect(url).toContain('/v3/assets/asset456/unpublish');
77-
expect(headers).toMatchObject({ api_version: '3.2' });
70+
const [url, , { headers }] = postStub.firstCall.args;
71+
expect(url).to.contain('/v3/assets/asset456/unpublish');
72+
expect(headers).to.include({ api_version: '3.2' });
7873
});
7974

8075
it('includes branch in headers alongside api_version when branch option is provided', async () => {
8176
await scheduleEntryAction(API_KEY, { ...ENTRY_OPTS, branch: 'feature-branch' });
8277

83-
const [, , { headers }] = mockPost.mock.calls[0];
84-
expect(headers).toMatchObject({ api_version: '3.2', branch: 'feature-branch' });
78+
const [, , { headers }] = postStub.firstCall.args;
79+
expect(headers).to.include({ api_version: '3.2', branch: 'feature-branch' });
8580
});
8681

8782
it('omits branch from headers when no branch option is given', async () => {
8883
await scheduleEntryAction(API_KEY, ENTRY_OPTS);
8984

90-
const [, , { headers }] = mockPost.mock.calls[0];
91-
expect(headers).not.toHaveProperty('branch');
85+
const [, , { headers }] = postStub.firstCall.args;
86+
expect(headers).to.not.have.property('branch');
9287
});
9388
});

0 commit comments

Comments
 (0)