-
Notifications
You must be signed in to change notification settings - Fork 2
Merge staging to development #196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,183 +1,192 @@ | ||
import * as contentstack from '../../src/lib/contentstack'; | ||
import { TEntry } from './types'; | ||
import dotenv from 'dotenv'; | ||
import * as contentstack from "../../src/lib/contentstack"; | ||
import { TEntry } from "./types"; | ||
import dotenv from "dotenv"; | ||
|
||
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 | ||
const entryUid = process.env.ENTRY_UID as string | ||
const previewToken = process.env.PREVIEW_TOKEN as string | ||
const managementToken = process.env.MANAGEMENT_TOKEN as string | ||
const host = process.env.HOST as string | ||
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; | ||
const entryUid = process.env.ENTRY_UID as string; | ||
const previewToken = process.env.PREVIEW_TOKEN as string; | ||
const managementToken = process.env.MANAGEMENT_TOKEN as string; | ||
const host = process.env.HOST 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); | ||
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', () => { | ||
const stack = contentstack.stack({ | ||
apiKey: apiKey, | ||
deliveryToken: deliveryToken, | ||
environment: environment, | ||
live_preview: { | ||
enable: true, | ||
management_token: managementToken, | ||
host: host | ||
} | ||
}) | ||
const livePreviewObject = stack.config.live_preview | ||
expect(livePreviewObject).not.toBeUndefined(); | ||
expect(livePreviewObject).toHaveProperty('enable'); | ||
expect(livePreviewObject).toHaveProperty('host'); | ||
expect(livePreviewObject).not.toHaveProperty('preview'); | ||
expect(stack.config.host).toBe('cdn.contentstack.io'); | ||
test("should check host when live preview is enabled and management token is provided", () => { | ||
const stack = contentstack.stack({ | ||
apiKey: apiKey, | ||
deliveryToken: deliveryToken, | ||
environment: environment, | ||
live_preview: { | ||
enable: true, | ||
management_token: managementToken, | ||
host: host, | ||
}, | ||
}); | ||
const livePreviewObject = stack.config.live_preview; | ||
expect(livePreviewObject).not.toBeUndefined(); | ||
expect(livePreviewObject).toHaveProperty("enable"); | ||
expect(livePreviewObject).toHaveProperty("host"); | ||
expect(livePreviewObject).not.toHaveProperty("preview"); | ||
expect(stack.config.host).toBe("cdn.contentstack.io"); | ||
}); | ||
|
||
test('should check host when live preview is disabled and management token is provided', () => { | ||
const stack = contentstack.stack({ | ||
apiKey: apiKey, | ||
deliveryToken: deliveryToken, | ||
environment: environment, | ||
live_preview: { | ||
enable: false, | ||
management_token: managementToken | ||
} | ||
}) | ||
const livePreviewObject = stack.config.live_preview | ||
expect(livePreviewObject).not.toBeUndefined(); | ||
expect(livePreviewObject).toHaveProperty('enable'); | ||
expect(livePreviewObject).not.toHaveProperty('host'); | ||
expect(livePreviewObject).not.toHaveProperty('preview'); | ||
expect(stack.config.host).toBe('cdn.contentstack.io'); | ||
test("should check host when live preview is disabled and management token is provided", () => { | ||
const stack = contentstack.stack({ | ||
apiKey: apiKey, | ||
deliveryToken: deliveryToken, | ||
environment: environment, | ||
live_preview: { | ||
enable: false, | ||
management_token: managementToken, | ||
}, | ||
}); | ||
const livePreviewObject = stack.config.live_preview; | ||
expect(livePreviewObject).not.toBeUndefined(); | ||
expect(livePreviewObject).toHaveProperty("enable"); | ||
expect(livePreviewObject).not.toHaveProperty("host"); | ||
expect(livePreviewObject).not.toHaveProperty("preview"); | ||
expect(stack.config.host).toBe("cdn.contentstack.io"); | ||
}); | ||
|
||
test('should check host when live preview is enabled and preview token is provided', () => { | ||
const stack = contentstack.stack({ | ||
apiKey: apiKey, | ||
deliveryToken: deliveryToken, | ||
environment: environment, | ||
live_preview: { | ||
enable: true, | ||
preview_token: previewToken, | ||
host: host | ||
} | ||
}) | ||
const livePreviewObject = stack.config.live_preview | ||
expect(livePreviewObject).not.toBeUndefined(); | ||
expect(livePreviewObject).toHaveProperty('enable'); | ||
expect(livePreviewObject).toHaveProperty('host'); | ||
expect(livePreviewObject).not.toHaveProperty('preview'); | ||
expect(stack.config.host).toBe('cdn.contentstack.io'); | ||
test("should check host when live preview is enabled and preview token is provided", () => { | ||
const stack = contentstack.stack({ | ||
apiKey: apiKey, | ||
deliveryToken: deliveryToken, | ||
environment: environment, | ||
live_preview: { | ||
enable: true, | ||
preview_token: previewToken, | ||
host: host, | ||
}, | ||
}); | ||
const livePreviewObject = stack.config.live_preview; | ||
expect(livePreviewObject).not.toBeUndefined(); | ||
expect(livePreviewObject).toHaveProperty("enable"); | ||
expect(livePreviewObject).toHaveProperty("host"); | ||
expect(livePreviewObject).not.toHaveProperty("preview"); | ||
expect(stack.config.host).toBe("cdn.contentstack.io"); | ||
}); | ||
|
||
test('should check host when live preview is disabled and preview token is provided', () => { | ||
const stack = contentstack.stack({ | ||
apiKey: apiKey, | ||
deliveryToken: deliveryToken, | ||
environment: environment, | ||
live_preview: { | ||
enable: false, | ||
preview_token: previewToken | ||
} | ||
}) | ||
const livePreviewObject = stack.config.live_preview | ||
expect(livePreviewObject).not.toBeUndefined(); | ||
expect(livePreviewObject).toHaveProperty('enable'); | ||
expect(livePreviewObject).not.toHaveProperty('host'); | ||
expect(livePreviewObject).not.toHaveProperty('preview'); | ||
expect(stack.config.host).toBe('cdn.contentstack.io'); | ||
test("should check host when live preview is disabled and preview token is provided", () => { | ||
const stack = contentstack.stack({ | ||
apiKey: apiKey, | ||
deliveryToken: deliveryToken, | ||
environment: environment, | ||
live_preview: { | ||
enable: false, | ||
preview_token: previewToken, | ||
}, | ||
}); | ||
const livePreviewObject = stack.config.live_preview; | ||
expect(livePreviewObject).not.toBeUndefined(); | ||
expect(livePreviewObject).toHaveProperty("enable"); | ||
expect(livePreviewObject).not.toHaveProperty("host"); | ||
expect(livePreviewObject).not.toHaveProperty("preview"); | ||
expect(stack.config.host).toBe("cdn.contentstack.io"); | ||
}); | ||
}); | ||
|
||
describe('Live preview query Entry API tests', () => { | ||
it('should check for entry when live preview is enabled with management token', async () => { | ||
try { | ||
const stack = contentstack.stack({ | ||
apiKey: process.env.API_KEY as string, | ||
deliveryToken: process.env.DELIVERY_TOKEN as string, | ||
environment: process.env.ENVIRONMENT as string, | ||
live_preview: { | ||
enable: true, | ||
management_token: managementToken, | ||
host: host | ||
} | ||
}) | ||
stack.livePreviewQuery({ | ||
contentTypeUid: 'blog_post', | ||
live_preview: 'ser', | ||
}) | ||
const result = await stack.contentType('blog_post').entry(entryUid).fetch<TEntry>(); | ||
expect(result).toBeDefined(); | ||
expect(result._version).toBeDefined(); | ||
expect(result.locale).toEqual('en-us'); | ||
expect(result.uid).toBeDefined(); | ||
expect(result.created_by).toBeDefined(); | ||
expect(result.updated_by).toBeDefined(); | ||
} catch (error: any) { | ||
expect(error).toBeDefined(); | ||
const errorData = JSON.parse(error.message); | ||
expect(errorData.status).toEqual(403); | ||
} | ||
}); | ||
describe("Live preview query Entry API tests", () => { | ||
it("should check for entry when live preview is enabled with management token", async () => { | ||
try { | ||
const stack = contentstack.stack({ | ||
apiKey: process.env.API_KEY as string, | ||
deliveryToken: process.env.DELIVERY_TOKEN as string, | ||
environment: process.env.ENVIRONMENT as string, | ||
live_preview: { | ||
enable: true, | ||
management_token: managementToken, | ||
host: host, | ||
}, | ||
}); | ||
stack.livePreviewQuery({ | ||
contentTypeUid: "blog_post", | ||
live_preview: "ser", | ||
}); | ||
const result = await stack | ||
.contentType("blog_post") | ||
.entry(entryUid) | ||
.fetch<TEntry>(); | ||
expect(result).toBeDefined(); | ||
expect(result._version).toBeDefined(); | ||
expect(result.locale).toEqual("en-us"); | ||
expect(result.uid).toBeDefined(); | ||
expect(result.created_by).toBeDefined(); | ||
expect(result.updated_by).toBeDefined(); | ||
} catch (error: any) { | ||
expect(error).toBeDefined(); | ||
const errorData = JSON.parse(error.message); | ||
expect(errorData.status).toEqual(403); | ||
} | ||
}); | ||
|
||
it('should check for entry is when live preview is disabled with managemenet token', async () => { | ||
const stack = contentstack.stack({ | ||
host: process.env.HOST as string, | ||
apiKey: process.env.API_KEY as string, | ||
deliveryToken: process.env.DELIVERY_TOKEN as string, | ||
environment: process.env.ENVIRONMENT as string, | ||
live_preview: { | ||
enable: false, | ||
management_token: managementToken | ||
} | ||
}) | ||
stack.livePreviewQuery({ | ||
contentTypeUid: 'blog_post', | ||
live_preview: 'ser', | ||
}) | ||
const result = await stack.contentType('blog_post').entry(entryUid).fetch<TEntry>(); | ||
expect(result).toBeDefined(); | ||
expect(result._version).toBeDefined(); | ||
expect(result.locale).toEqual('en-us'); | ||
expect(result.uid).toBeDefined(); | ||
expect(result.created_by).toBeDefined(); | ||
expect(result.updated_by).toBeDefined(); | ||
it("should check for entry is when live preview is disabled with management token", async () => { | ||
const stack = contentstack.stack({ | ||
host: process.env.HOST as string, | ||
apiKey: process.env.API_KEY as string, | ||
deliveryToken: process.env.DELIVERY_TOKEN as string, | ||
environment: process.env.ENVIRONMENT as string, | ||
live_preview: { | ||
enable: false, | ||
management_token: managementToken, | ||
}, | ||
}); | ||
stack.livePreviewQuery({ | ||
contentTypeUid: "blog_post", | ||
live_preview: "ser", | ||
}); | ||
const result = await stack | ||
.contentType("blog_post") | ||
.entry(entryUid) | ||
.fetch<TEntry>(); | ||
expect(result).toBeDefined(); | ||
expect(result._version).toBeDefined(); | ||
expect(result.locale).toEqual("en-us"); | ||
expect(result.uid).toBeDefined(); | ||
expect(result.created_by).toBeDefined(); | ||
expect(result.updated_by).toBeDefined(); | ||
}); | ||
|
||
it('should check for entry is when live preview is disabled with preview token', async () => { | ||
const stack = contentstack.stack({ | ||
host: process.env.HOST as string, | ||
apiKey: process.env.API_KEY as string, | ||
deliveryToken: process.env.DELIVERY_TOKEN as string, | ||
environment: process.env.ENVIRONMENT as string, | ||
live_preview: { | ||
enable: false, | ||
preview_token: previewToken | ||
} | ||
}) | ||
stack.livePreviewQuery({ | ||
contentTypeUid: 'blog_post', | ||
live_preview: 'ser', | ||
}) | ||
const result = await stack.contentType('blog_post').entry(entryUid).fetch<TEntry>(); | ||
expect(result).toBeDefined(); | ||
expect(result._version).toBeDefined(); | ||
expect(result.locale).toEqual('en-us'); | ||
expect(result.uid).toBeDefined(); | ||
expect(result.created_by).toBeDefined(); | ||
expect(result.updated_by).toBeDefined(); | ||
it("should check for entry is when live preview is disabled with preview token", async () => { | ||
const stack = contentstack.stack({ | ||
host: process.env.HOST as string, | ||
apiKey: process.env.API_KEY as string, | ||
deliveryToken: process.env.DELIVERY_TOKEN as string, | ||
environment: process.env.ENVIRONMENT as string, | ||
live_preview: { | ||
enable: false, | ||
preview_token: previewToken, | ||
}, | ||
}); | ||
}) | ||
stack.livePreviewQuery({ | ||
contentTypeUid: "blog_post", | ||
live_preview: "ser", | ||
}); | ||
const result = await stack | ||
.contentType("blog_post") | ||
.entry(entryUid) | ||
.fetch<TEntry>(); | ||
expect(result).toBeDefined(); | ||
expect(result._version).toBeDefined(); | ||
expect(result.locale).toEqual("en-us"); | ||
expect(result.uid).toBeDefined(); | ||
expect(result.created_by).toBeDefined(); | ||
expect(result.updated_by).toBeDefined(); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.