Skip to content

Commit 411be70

Browse files
cs-rajclaude
andcommitted
test(external-migrate): add scheduleEntryAction api_version header assertions
Covers all four publish/unpublish paths (entry publish, entry unpublish, asset publish via sys_assets, asset unpublish via sys_assets) and verifies api_version: '3.2' is present in headers on every call. Also asserts branch header inclusion and omission. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent c5bc3a7 commit 411be70

2 files changed

Lines changed: 95 additions & 0 deletions

File tree

.talismanrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ fileignoreconfig:
1717
checksum: ca699a9d73757d44ded4d9d27beb4f460f911a7c88a14551a9402a3ac0c69873
1818
- filename: packages/contentstack-external-migrate/src/lib/create-stack.ts
1919
checksum: 68a9510db6f2746ac5006c091d276c1ba619a9e15c76a3edae3967e4f9c2dd4e
20+
- filename: packages/contentstack-external-migrate/test/lib/create-stack.test.ts
21+
checksum: 45af4e45e4baadf7e418a11a46a6243b8ffabafdbf32d0269d89c5d3db837a13
2022
- filename: CHANGELOG.md
2123
checksum: 88c7e1dee308fa4ae25e7815ead0842b1aac7ed669b02859cc8b25cba879595d
2224
- filename: packages/contentstack-bulk-operations/test/unit/services/taxonomy-service.test.ts
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import { beforeEach, describe, expect, it, vi } from 'vitest';
2+
import { scheduleEntryAction } from '../../src/lib/create-stack';
3+
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+
22+
describe('scheduleEntryAction', () => {
23+
const API_KEY = 'blt-test-api-key';
24+
const ENTRY_OPTS = {
25+
contentTypeUid: 'blog',
26+
entryUid: 'entry123',
27+
action: 'publish' as const,
28+
environment: 'development',
29+
locale: 'en-us',
30+
scheduledAt: '2026-08-01T10:00:00.000Z',
31+
};
32+
33+
beforeEach(() => {
34+
mockPost.mockReset();
35+
mockPost.mockResolvedValue({ data: {} });
36+
});
37+
38+
it('sends api_version: 3.2 header on entry publish', async () => {
39+
await scheduleEntryAction(API_KEY, ENTRY_OPTS);
40+
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' });
45+
});
46+
47+
it('sends api_version: 3.2 header on entry unpublish', async () => {
48+
await scheduleEntryAction(API_KEY, { ...ENTRY_OPTS, action: 'unpublish' });
49+
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' });
53+
});
54+
55+
it('sends api_version: 3.2 header on asset publish (sys_assets)', async () => {
56+
await scheduleEntryAction(API_KEY, {
57+
...ENTRY_OPTS,
58+
contentTypeUid: 'sys_assets',
59+
entryUid: 'asset456',
60+
});
61+
62+
const [url, , { headers }] = mockPost.mock.calls[0];
63+
expect(url).toContain('/v3/assets/asset456/publish');
64+
expect(headers).toMatchObject({ api_version: '3.2' });
65+
});
66+
67+
it('sends api_version: 3.2 header on asset unpublish (sys_assets)', async () => {
68+
await scheduleEntryAction(API_KEY, {
69+
...ENTRY_OPTS,
70+
contentTypeUid: 'sys_assets',
71+
entryUid: 'asset456',
72+
action: 'unpublish',
73+
});
74+
75+
const [url, , { headers }] = mockPost.mock.calls[0];
76+
expect(url).toContain('/v3/assets/asset456/unpublish');
77+
expect(headers).toMatchObject({ api_version: '3.2' });
78+
});
79+
80+
it('includes branch in headers alongside api_version when branch option is provided', async () => {
81+
await scheduleEntryAction(API_KEY, { ...ENTRY_OPTS, branch: 'feature-branch' });
82+
83+
const [, , { headers }] = mockPost.mock.calls[0];
84+
expect(headers).toMatchObject({ api_version: '3.2', branch: 'feature-branch' });
85+
});
86+
87+
it('omits branch from headers when no branch option is given', async () => {
88+
await scheduleEntryAction(API_KEY, ENTRY_OPTS);
89+
90+
const [, , { headers }] = mockPost.mock.calls[0];
91+
expect(headers).not.toHaveProperty('branch');
92+
});
93+
});

0 commit comments

Comments
 (0)