1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Parsing app release date from the package version

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2022-05-26 11:28:01 +03:00
parent c9f105405f
commit c2c9c93b54
2 changed files with 41 additions and 3 deletions

View File

@ -3,12 +3,17 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { DiContainer } from "@ogre-tools/injectable";
import appVersionInjectable from "../../../common/get-configuration-file-model/app-version/app-version.injectable";
import { getDiForUnitTesting } from "../../getDiForUnitTesting";
import appPublishDateInjectable from "../app-publish-date.injectable";
describe("appPublishDate", () => {
const di = getDiForUnitTesting({ doGeneralOverrides: true });
let di: DiContainer;
beforeEach(() => {
di = getDiForUnitTesting({ doGeneralOverrides: true });
});
it("should return empty string if appVersion is not provided", () => {
di.override(appVersionInjectable, () => "");
@ -17,4 +22,28 @@ describe("appPublishDate", () => {
expect(appPublishDate).toBe("");
});
it("should return empty string if version without date provided", () => {
di.override(appVersionInjectable, () => "5.6.0-alpha.0");
const appPublishDate = di.inject(appPublishDateInjectable);
expect(appPublishDate).toBe("");
});
it("should return empty string if invalid version date provided", () => {
di.override(appVersionInjectable, () => "5.6.0-alpha.2021-23-1.0");
const appPublishDate = di.inject(appPublishDateInjectable);
expect(appPublishDate).toBe("");
});
it("should return proper date if version with date provided", () => {
di.override(appVersionInjectable, () => "5.4.6-latest.20220428.1");
const appPublishDate = di.inject(appPublishDateInjectable);
expect(appPublishDate).toBe("2022-04-28");
});
});

View File

@ -3,6 +3,15 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
export function appPublishDate(appVersion: string) {
return "";
import moment from "moment";
export function appPublishDate(appVersion = "") {
const dateFromVersion = appVersion.match(/\d{8}/);
const date = moment(dateFromVersion?.[0], "YYYYMMDD");
if (!date.isValid()) {
return "";
}
return date.format("YYYY-MM-DD");
}