-
Notifications
You must be signed in to change notification settings - Fork 8.6k
cloud: add isInTrial helper function #239210
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
Changes from all commits
c48cb77
25f3834
76802f2
c55cb10
7eac841
87075c8
122d8af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -163,42 +163,83 @@ describe('Cloud Plugin', () => { | |
| }); | ||
| expect(setup.isServerlessEnabled).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| it('exposes `serverless.projectId`', () => { | ||
| const { setup } = setupPlugin({ | ||
| serverless: { | ||
| project_id: 'my-awesome-project', | ||
| }, | ||
| it('exposes `serverless.projectId`', () => { | ||
| const { setup } = setupPlugin({ | ||
| serverless: { | ||
| project_id: 'my-awesome-project', | ||
| }, | ||
| }); | ||
| expect(setup.serverless.projectId).toBe('my-awesome-project'); | ||
| }); | ||
| expect(setup.serverless.projectId).toBe('my-awesome-project'); | ||
| }); | ||
|
|
||
| it('exposes `serverless.projectName`', () => { | ||
| const { setup } = setupPlugin({ | ||
| serverless: { | ||
| project_id: 'my-awesome-project', | ||
| project_name: 'My Awesome Project', | ||
| }, | ||
| it('exposes `serverless.projectName`', () => { | ||
| const { setup } = setupPlugin({ | ||
| serverless: { | ||
| project_id: 'my-awesome-project', | ||
| project_name: 'My Awesome Project', | ||
| }, | ||
| }); | ||
| expect(setup.serverless.projectName).toBe('My Awesome Project'); | ||
| }); | ||
| expect(setup.serverless.projectName).toBe('My Awesome Project'); | ||
| }); | ||
|
|
||
| it('exposes `serverless.projectType`', () => { | ||
| const { setup } = setupPlugin({ | ||
| serverless: { | ||
| project_id: 'my-awesome-project', | ||
| project_name: 'My Awesome Project', | ||
| project_type: 'security', | ||
| }, | ||
| it('exposes `serverless.projectType`', () => { | ||
| const { setup } = setupPlugin({ | ||
| serverless: { | ||
| project_id: 'my-awesome-project', | ||
| project_name: 'My Awesome Project', | ||
| project_type: 'security', | ||
| }, | ||
| }); | ||
| expect(setup.serverless.projectType).toBe('security'); | ||
| }); | ||
| describe('exposes isInTrial', () => { | ||
| it('is `true` when `serverless.in_trial` is set', () => { | ||
| const { setup } = setupPlugin({ | ||
| serverless: { | ||
| project_id: 'my-awesome-project', | ||
| in_trial: true, | ||
| }, | ||
| }); | ||
|
|
||
| expect(setup.isInTrial()).toBe(true); | ||
| }); | ||
| it('is `false` when `serverless.in_trial` is set to false', () => { | ||
| const { setup } = setupPlugin({ | ||
| serverless: { | ||
| project_id: 'my-awesome-project', | ||
| in_trial: false, | ||
| }, | ||
| }); | ||
| expect(setup.isInTrial()).toBe(false); | ||
| }); | ||
| }); | ||
| expect(setup.serverless.projectType).toBe('security'); | ||
| }); | ||
|
|
||
| it('exposes fetchElasticsearchConfig', async () => { | ||
| const { setup } = setupPlugin(); | ||
| const result = await setup.fetchElasticsearchConfig(); | ||
| expect(result).toEqual({ elasticsearchUrl: 'elasticsearch-url' }); | ||
| }); | ||
| describe('exposes isInTrial', () => { | ||
| it('is `true` when `trial_end_date` is set and is in the future', () => { | ||
| const { setup } = setupPlugin({ | ||
| trial_end_date: new Date(Date.now() + 10000).toISOString(), | ||
| }); | ||
|
|
||
| expect(setup.isInTrial()).toBe(true); | ||
| }); | ||
| it('is `false` when `trial_end_date` is set and is in the past', () => { | ||
| const { setup } = setupPlugin({ | ||
| trial_end_date: new Date(Date.now() - 10000).toISOString(), | ||
| }); | ||
|
|
||
| expect(setup.isInTrial()).toBe(false); | ||
| }); | ||
| it('is `false` when `serverless.in_trial` & `trial_end_date` are not set', () => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens when both
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jloleysens I will remove all I can add code to throw if both are set, but that makes me a little uneasy since both of these config values are set from other systems. I feel like it's more likely someone will break Kibana unwittingly.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The tests below are testing the I will move the |
||
| const { setup } = setupPlugin({}); | ||
| expect(setup.isInTrial()).toBe(false); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
|
|
@@ -300,30 +341,31 @@ describe('Cloud Plugin', () => { | |
| const start = plugin.start(coreStart); | ||
| expect(start.isServerlessEnabled).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| it('exposes `serverless.projectId`', () => { | ||
| const { plugin } = startPlugin({ | ||
| serverless: { | ||
| project_id: 'my-awesome-project', | ||
| }, | ||
| it('exposes `serverless.projectId`', () => { | ||
| const { plugin } = startPlugin({ | ||
| serverless: { | ||
| project_id: 'my-awesome-project', | ||
| }, | ||
| }); | ||
| const coreStart = coreMock.createStart(); | ||
| const start = plugin.start(coreStart); | ||
| expect(start.serverless.projectId).toBe('my-awesome-project'); | ||
| }); | ||
| const coreStart = coreMock.createStart(); | ||
| const start = plugin.start(coreStart); | ||
| expect(start.serverless.projectId).toBe('my-awesome-project'); | ||
| }); | ||
|
|
||
| it('exposes `serverless.projectName`', () => { | ||
| const { plugin } = startPlugin({ | ||
| serverless: { | ||
| project_id: 'my-awesome-project', | ||
| project_name: 'My Awesome Project', | ||
| }, | ||
| it('exposes `serverless.projectName`', () => { | ||
| const { plugin } = startPlugin({ | ||
| serverless: { | ||
| project_id: 'my-awesome-project', | ||
| project_name: 'My Awesome Project', | ||
| }, | ||
| }); | ||
| const coreStart = coreMock.createStart(); | ||
| const start = plugin.start(coreStart); | ||
| expect(start.serverless.projectName).toBe('My Awesome Project'); | ||
| }); | ||
| const coreStart = coreMock.createStart(); | ||
| const start = plugin.start(coreStart); | ||
| expect(start.serverless.projectName).toBe('My Awesome Project'); | ||
| }); | ||
|
|
||
| it('exposes fetchElasticsearchConfig', async () => { | ||
| const { plugin } = startPlugin(); | ||
| const coreStart = coreMock.createStart(); | ||
|
|
@@ -332,5 +374,38 @@ describe('Cloud Plugin', () => { | |
| const result = await start.fetchElasticsearchConfig(); | ||
| expect(result).toEqual({ elasticsearchUrl: 'elasticsearch-url' }); | ||
| }); | ||
| describe('exposes isInTrial', () => { | ||
| const getStart = (configParts: Partial<CloudConfigType> = {}) => { | ||
| const { plugin } = startPlugin(configParts); | ||
| const coreStart = coreMock.createStart(); | ||
| coreStart.http.get.mockResolvedValue({ elasticsearch_url: 'elasticsearch-url' }); | ||
| return plugin.start(coreStart); | ||
| }; | ||
| it('is `true` when `trial_end_date` is set and is in the future', () => { | ||
| const pluginStart = getStart({ | ||
| trial_end_date: new Date(Date.now() + 10000).toISOString(), | ||
| }); | ||
|
|
||
| expect(pluginStart.isInTrial()).toBe(true); | ||
| }); | ||
| it('is `false` when `trial_end_date` is set and is in the past', () => { | ||
| const pluginStart = getStart({ | ||
| trial_end_date: new Date(Date.now() - 10000).toISOString(), | ||
| }); | ||
|
|
||
| expect(pluginStart.isInTrial()).toBe(false); | ||
| }); | ||
| it('is `false` when `trial_end_date` is not a valid date', () => { | ||
| const pluginStart = getStart({ | ||
| trial_end_date: 'invalid-date', | ||
| }); | ||
|
|
||
| expect(pluginStart.isInTrial()).toBe(false); | ||
| }); | ||
| it('is `false` when `serverless.in_trial` & `trial_end_date` are not set', () => { | ||
| const pluginStart = getStart(); | ||
| expect(pluginStart.isInTrial()).toBe(false); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like we're removing knowledge of "endDate"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, other plugins should just use the function and let the cloud plugin handle all the logic around endDate.