feat(caprover): allow human to mark an app as successfully updated
parent
5c599842f6
commit
204efe8a8b
@ -0,0 +1,15 @@
|
|||||||
|
import DomainEvent from "../DomainEvent";
|
||||||
|
|
||||||
|
type ApplicationUpdateFinishedPayload = {
|
||||||
|
id: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export class ApplicationUpdateFinished
|
||||||
|
implements DomainEvent<ApplicationUpdateFinishedPayload>
|
||||||
|
{
|
||||||
|
readonly type = "ApplicationUpdateFinished" as const;
|
||||||
|
constructor(
|
||||||
|
public readonly payload: ApplicationUpdateFinishedPayload,
|
||||||
|
public readonly createdAt: Date
|
||||||
|
) {}
|
||||||
|
}
|
@ -0,0 +1,99 @@
|
|||||||
|
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" },
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,20 @@
|
|||||||
|
import { describe, expect, it } from "bun:test";
|
||||||
|
import { TestApp } from "../domain/testing/TestApp";
|
||||||
|
import Human from "./Human";
|
||||||
|
|
||||||
|
describe("Human", () => {
|
||||||
|
it("should mark the application as updated", () => {
|
||||||
|
const eventStore = new TestApp().eventStore;
|
||||||
|
const human = new Human(eventStore);
|
||||||
|
|
||||||
|
const appName = "MyApp";
|
||||||
|
human.markApplicationAsUpdated(appName);
|
||||||
|
|
||||||
|
const events = eventStore.getAllEvents();
|
||||||
|
expect(events).toBeArrayOfSize(1);
|
||||||
|
expect(events[0]).toMatchObject({
|
||||||
|
type: "ApplicationUpdateFinished",
|
||||||
|
payload: { id: "MyApp" },
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,17 @@
|
|||||||
|
import EventStore from "../domain/EventStore";
|
||||||
|
import { ApplicationUpdateFinished } from "../domain/events/ApplicationUpdateFinished";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Actions done by a Human in the application
|
||||||
|
*/
|
||||||
|
class Human {
|
||||||
|
constructor(private eventStore: EventStore) {}
|
||||||
|
|
||||||
|
markApplicationAsUpdated(appName: string) {
|
||||||
|
this.eventStore.append(
|
||||||
|
new ApplicationUpdateFinished({ id: appName }, new Date())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Human;
|
Loading…
Reference in New Issue