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" }, ]); }); }); });