Skip to content
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

[7.x] [Newsfeed] Ensure the version format when calling the API (#76381) #76623

Merged
merged 1 commit into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/plugins/newsfeed/public/lib/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Object.defineProperty(window, 'sessionStorage', {
});

describe('NewsfeedApiDriver', () => {
const kibanaVersion = 'test_version';
const kibanaVersion = '99.999.9-test_version'; // It'll remove the `-test_version` bit
const userLanguage = 'en';
const fetchInterval = 2000;
const getDriver = () => new NewsfeedApiDriver(kibanaVersion, userLanguage, fetchInterval);
Expand Down Expand Up @@ -179,7 +179,7 @@ describe('NewsfeedApiDriver', () => {
"error": null,
"feedItems": Array [],
"hasNew": false,
"kibanaVersion": "test_version",
"kibanaVersion": "99.999.9",
}
`);
});
Expand Down Expand Up @@ -227,7 +227,7 @@ describe('NewsfeedApiDriver', () => {
},
],
hasNew: true,
kibanaVersion: 'test_version',
kibanaVersion: '99.999.9',
});
});

Expand Down Expand Up @@ -309,7 +309,7 @@ describe('NewsfeedApiDriver', () => {
},
],
hasNew: true,
kibanaVersion: 'test_version',
kibanaVersion: '99.999.9',
});
});

Expand Down Expand Up @@ -375,7 +375,7 @@ describe('NewsfeedApiDriver', () => {
},
],
hasNew: true,
kibanaVersion: 'test_version',
kibanaVersion: '99.999.9',
});
});

Expand Down Expand Up @@ -405,7 +405,7 @@ describe('NewsfeedApiDriver', () => {
"error": null,
"feedItems": Array [],
"hasNew": false,
"kibanaVersion": "test_version",
"kibanaVersion": "99.999.9",
}
`);
});
Expand Down Expand Up @@ -436,7 +436,7 @@ describe('NewsfeedApiDriver', () => {
"error": null,
"feedItems": Array [],
"hasNew": false,
"kibanaVersion": "test_version",
"kibanaVersion": "99.999.9",
}
`);
});
Expand Down
8 changes: 6 additions & 2 deletions src/plugins/newsfeed/public/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@ import { ApiItem, NewsfeedItem, FetchResult, NewsfeedPluginBrowserConfig } from
type ApiConfig = NewsfeedPluginBrowserConfig['service'];

export class NewsfeedApiDriver {
private readonly kibanaVersion: string;
private readonly loadedTime = moment().utc(); // the date is compared to time in UTC format coming from the service

constructor(
private readonly kibanaVersion: string,
kibanaVersion: string,
private readonly userLanguage: string,
private readonly fetchInterval: number
) {}
) {
// The API only accepts versions in the format `X.Y.Z`, so we need to drop the `-SNAPSHOT` or any other label after it
this.kibanaVersion = kibanaVersion.replace(/^(\d+\.\d+\.\d+).*/, '$1');
}

shouldFetch(): boolean {
const lastFetchUtc: string | null = sessionStorage.getItem(NEWSFEED_LAST_FETCH_STORAGE_KEY);
Expand Down
2 changes: 1 addition & 1 deletion test/common/fixtures/plugins/newsfeed/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class NewsFeedSimulatorPlugin implements Plugin {

public setup({ http }: CoreSetup) {
const router = http.createRouter();
const version = this.initializerContext.env.packageInfo.version;
const version = this.initializerContext.env.packageInfo.version.replace('-SNAPSHOT', '');

router.get(
{
Expand Down