-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Store pipeline definitions in DB (#1452)
This backs the `PipelineDefinitionDB` on to the Postgres DB. It's quite crude and is also missing user-management features, but it works for being able to start pipelines outside of tests. I've avoided doing user-management code since that overlaps with #1451
- Loading branch information
Showing
6 changed files
with
247 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,8 @@ import * as path from "path"; | |
import { ILemonadeAPI } from "../src/apis/lemonade/lemonadeAPI"; | ||
import { getI18nString } from "../src/apis/pretix/genericPretixAPI"; | ||
import { stopApplication } from "../src/application"; | ||
import { PipelineDefinitionDB } from "../src/database/queries/pipelineDefinitionDB"; | ||
import { sqlQuery } from "../src/database/sqlQuery"; | ||
import { GenericIssuanceService } from "../src/services/generic-issuance/genericIssuanceService"; | ||
import { | ||
LemonadePipeline, | ||
|
@@ -217,8 +219,10 @@ describe("generic issuance service tests", function () { | |
|
||
const lemonadeAPI: ILemonadeAPI = new MockLemonadeAPI(mockLemonadeData); | ||
|
||
const pipelineOwnerUUID = randomUUID(); | ||
|
||
const lemonadeDefinition: LemonadePipelineDefinition = { | ||
ownerUserId: randomUUID(), | ||
ownerUserId: pipelineOwnerUUID, | ||
id: randomUUID(), | ||
editorUserIds: [], | ||
options: { | ||
|
@@ -257,7 +261,7 @@ describe("generic issuance service tests", function () { | |
const checkerPretixEmail = pretixOrganizer.EMAIL_1; | ||
|
||
const pretixDefinition: PretixPipelineDefinition = { | ||
ownerUserId: randomUUID(), | ||
ownerUserId: pipelineOwnerUUID, | ||
id: randomUUID(), | ||
editorUserIds: [], | ||
options: { | ||
|
@@ -297,6 +301,13 @@ describe("generic issuance service tests", function () { | |
lemonadeAPI | ||
}); | ||
|
||
// TODO: remove this once we have user management | ||
await sqlQuery( | ||
application.context.dbPool, | ||
"INSERT INTO generic_issuance_users VALUES($1, $2, $3)", | ||
[pipelineOwnerUUID, "[email protected]", true] | ||
); | ||
|
||
const orgUrls = mockPretixData.get().organizersByOrgUrl.keys(); | ||
mockPretixServer = getGenericMockPretixAPIServer(orgUrls, mockPretixData); | ||
mockPretixServer.listen({ onUnhandledRequest: "bypass" }); | ||
|
@@ -305,10 +316,11 @@ describe("generic issuance service tests", function () { | |
URL_ROOT = application.expressContext.localEndpoint; | ||
giService = application.services.genericIssuanceService; | ||
await giService?.stop(); | ||
await application.context.pipelineDefinitionDB.clearAllDefinitions(); | ||
await application.context.pipelineDefinitionDB.setDefinitions( | ||
pipelineDefinitions | ||
const pipelineDefinitionDB = new PipelineDefinitionDB( | ||
application.context.dbPool | ||
); | ||
await pipelineDefinitionDB.clearAllDefinitions(); | ||
await pipelineDefinitionDB.setDefinitions(pipelineDefinitions); | ||
await giService?.start(); | ||
}); | ||
|
||
|
@@ -462,6 +474,56 @@ describe("generic issuance service tests", function () { | |
expect(thirdCheckinResult.success).to.eq(false); | ||
}); | ||
|
||
it("test definition DB", async function () { | ||
const definitionDB = new PipelineDefinitionDB(application.context.dbPool); | ||
await definitionDB.clearAllDefinitions(); | ||
|
||
{ | ||
const definitions = await definitionDB.loadPipelineDefinitions(); | ||
expect(definitions).to.be.empty; | ||
} | ||
|
||
{ | ||
await definitionDB.setDefinitions(pipelineDefinitions); | ||
const definitions = await definitionDB.loadPipelineDefinitions(); | ||
expect(definitions.length).to.eq(2); | ||
|
||
const pretixDefinition = definitions.find( | ||
(d) => d.type === PipelineType.Pretix | ||
) as PretixPipelineDefinition; | ||
const newKey = "TEST_KEY"; | ||
pretixDefinition.options = { | ||
...pretixDefinition?.options, | ||
pretixAPIKey: newKey | ||
}; | ||
await definitionDB.setDefinition(pretixDefinition); | ||
const updatedPretixDefinition = (await definitionDB.getDefinition( | ||
pretixDefinition.id | ||
)) as PretixPipelineDefinition; | ||
expect(updatedPretixDefinition).to.exist; | ||
expect( | ||
(updatedPretixDefinition as PretixPipelineDefinition).options | ||
.pretixAPIKey | ||
).to.eq(newKey); | ||
|
||
updatedPretixDefinition.editorUserIds.push(pipelineOwnerUUID); | ||
await definitionDB.setDefinition(updatedPretixDefinition); | ||
const newEditorDefinition = (await definitionDB.getDefinition( | ||
updatedPretixDefinition.id | ||
)) as PretixPipelineDefinition; | ||
expect(newEditorDefinition).to.exist; | ||
expect(newEditorDefinition.editorUserIds).to.contain(pipelineOwnerUUID); | ||
|
||
newEditorDefinition.editorUserIds = []; | ||
await definitionDB.setDefinition(newEditorDefinition); | ||
const emptyEditorsDefinition = (await definitionDB.getDefinition( | ||
updatedPretixDefinition.id | ||
)) as PretixPipelineDefinition; | ||
expect(emptyEditorsDefinition).to.exist; | ||
expect(emptyEditorsDefinition.editorUserIds).to.be.empty; | ||
} | ||
}); | ||
|
||
this.afterAll(async () => { | ||
await stopApplication(application); | ||
mockPretixServer.close(); | ||
|