You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
3.2 KiB
TypeScript

import { beforeEach, describe, expect, it } from "bun:test";
import { TestApp } from "../testing/TestApp";
import { ApplicationUpdateStarted } from "../events/ApplicationUpdateStarted";
import { ApplicationUpdateFinished } from "../events/ApplicationUpdateFinished";
describe("ApplicationUpdates", () => {
describe("getPendingUpdates", () => {
it("should return an empty array when there are no pending updates", () => {
const app = new TestApp();
expect(app.projections.ApplicationUpdates.getPendingUpdates()).toEqual(
[]
);
});
it("should return all pending updates when several started", () => {
const app = new TestApp([
new ApplicationUpdateStarted(
{ id: "mail", newVersion: "1.0.0" },
new Date()
),
new ApplicationUpdateStarted(
{ id: "blog", newVersion: "10.0.1" },
new Date()
),
]);
const updates = app.projections.ApplicationUpdates.getPendingUpdates();
expect(updates).toEqual([
{ id: "mail", newVersion: "1.0.0" },
{ id: "blog", newVersion: "10.0.1" },
]);
});
it("should return all pending updates for an application while it isn't successfull", () => {
const app = new TestApp([
new ApplicationUpdateStarted(
{ id: "mail", newVersion: "1.0.0" },
new Date()
),
new ApplicationUpdateStarted(
{ id: "blog", newVersion: "10.0.1" },
new Date()
),
new ApplicationUpdateStarted(
{ id: "mail", newVersion: "1.0.1" },
new Date()
),
]);
const updates = app.projections.ApplicationUpdates.getPendingUpdates();
expect(updates).toEqual([
{ id: "mail", newVersion: "1.0.0" },
{ id: "blog", newVersion: "10.0.1" },
{ id: "mail", newVersion: "1.0.1" },
]);
});
it("should not return updates for applications after they were marked as successful", () => {
const app = new TestApp([
new ApplicationUpdateStarted(
{ id: "mail", newVersion: "1.0.0" },
new Date()
),
new ApplicationUpdateStarted(
{ id: "blog", newVersion: "10.0.1" },
new Date()
),
new ApplicationUpdateFinished({ id: "mail" }, new Date()),
]);
const updates = app.projections.ApplicationUpdates.getPendingUpdates();
expect(updates).toEqual([{ id: "blog", newVersion: "10.0.1" }]);
});
it("should consider the latest update for an application", () => {
const app = new TestApp([
new ApplicationUpdateStarted(
{ id: "mail", newVersion: "1.0.0" },
new Date()
),
new ApplicationUpdateStarted(
{ id: "blog", newVersion: "4.2.0" },
new Date()
),
new ApplicationUpdateFinished({ id: "mail" }, new Date()),
new ApplicationUpdateStarted(
{ id: "mail", newVersion: "1.0.1" },
new Date()
),
]);
const updates = app.projections.ApplicationUpdates.getPendingUpdates();
expect(updates).toEqual([
{ id: "blog", newVersion: "4.2.0" },
{ id: "mail", newVersion: "1.0.1" },
]);
});
});
});