Skip to content

Commit 1d1c9fa

Browse files
authored
Merge pull request #8 from contentstack/feat/DX-533-branch-in-stack-config
feat: branch property in stack config
2 parents c7f6d58 + e6276f5 commit 1d1c9fa

File tree

4 files changed

+10
-0
lines changed

4 files changed

+10
-0
lines changed

src/lib/contentstack.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ export function stack(config: StackConfig): StackClass {
6969
throw new Error('Environment for Stack is required');
7070
}
7171

72+
if (config.branch) {
73+
defaultConfig.headers.branch = config.branch;
74+
}
75+
7276
if (config.early_access) {
7377
defaultConfig.headers['x-header-ea'] = config.early_access.join(',');
7478
}

src/lib/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface StackConfig extends HttpClientParams {
1414
apiKey: string;
1515
deliveryToken: string;
1616
environment: string;
17+
branch?: string;
1718
early_access?: string[];
1819
region?: Region;
1920
locale?: string;

test/api/live-preview.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,20 @@ dotenv.config();
77
const apiKey = process.env.API_KEY as string
88
const deliveryToken = process.env.DELIVERY_TOKEN as string
99
const environment = process.env.ENVIRONMENT as string
10+
const branch = process.env.BRANCH as string
1011

1112
describe('Live preview tests', () => {
1213
test('should check for values initialized', () => {
1314
const stack = contentstack.stack({
1415
apiKey: apiKey,
1516
deliveryToken: deliveryToken,
1617
environment: environment,
18+
branch: branch,
1719
});
1820
const livePreviewObject = stack.config.live_preview;
1921
expect(livePreviewObject).toBeUndefined();
2022
expect(stack.config.host).toBe('cdn.contentstack.io');
23+
expect(stack.config.branch).toBe(branch);
2124
});
2225

2326
test('should check host when live preview is enabled and management token is provided', () => {

test/unit/contentstack.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,14 @@ describe('Contentstack', () => {
9797
apiKey: 'apiKey',
9898
deliveryToken: 'delivery',
9999
environment: 'env',
100+
branch: 'branch',
100101
};
101102
const stackInstance = createStackInstance(config);
102103
expect(stackInstance).toBeInstanceOf(Stack);
103104
expect(stackInstance.config.apiKey).toEqual(config.apiKey);
104105
expect(stackInstance.config.deliveryToken).toEqual(config.deliveryToken);
105106
expect(stackInstance.config.environment).toEqual(config.environment);
107+
expect(stackInstance.config.branch).toEqual(config.branch);
106108
done();
107109
});
108110

0 commit comments

Comments
 (0)