Skip to content

Commit

Permalink
feat: branch property in stack config
Browse files Browse the repository at this point in the history
  • Loading branch information
nadeem-cs committed May 23, 2024
1 parent 72a7ea0 commit 9b5db44
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/lib/contentstack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ export function stack(config: StackConfig): StackClass {
throw new Error('Environment for Stack is required');
}

if (config.branch) {
defaultConfig.headers.branch = config.branch;
}

if (config.early_access) {
defaultConfig.headers['x-header-ea'] = config.early_access.join(',');
}
Expand Down
1 change: 1 addition & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface StackConfig extends HttpClientParams {
apiKey: string;
deliveryToken: string;
environment: string;
branch?: string;
early_access?: string[];
region?: Region;
locale?: string;
Expand Down
3 changes: 3 additions & 0 deletions test/api/live-preview.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@ dotenv.config();
const apiKey = process.env.API_KEY as string
const deliveryToken = process.env.DELIVERY_TOKEN as string
const environment = process.env.ENVIRONMENT as string
const branch = process.env.BRANCH as string

describe('Live preview tests', () => {
test('should check for values initialized', () => {
const stack = contentstack.stack({
apiKey: apiKey,
deliveryToken: deliveryToken,
environment: environment,
branch: branch,
});
const livePreviewObject = stack.config.live_preview;
expect(livePreviewObject).toBeUndefined();
expect(stack.config.host).toBe('cdn.contentstack.io');
expect(stack.config.branch).toBe(branch);
});

test('should check host when live preview is enabled and management token is provided', () => {
Expand Down
2 changes: 2 additions & 0 deletions test/unit/contentstack.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,14 @@ describe('Contentstack', () => {
apiKey: 'apiKey',
deliveryToken: 'delivery',
environment: 'env',
branch: 'branch',
};
const stackInstance = createStackInstance(config);
expect(stackInstance).toBeInstanceOf(Stack);
expect(stackInstance.config.apiKey).toEqual(config.apiKey);
expect(stackInstance.config.deliveryToken).toEqual(config.deliveryToken);
expect(stackInstance.config.environment).toEqual(config.environment);
expect(stackInstance.config.branch).toEqual(config.branch);
done();
});

Expand Down

0 comments on commit 9b5db44

Please sign in to comment.