-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #123 from codegouvfr/test-backend-routes
test backend routes
- Loading branch information
Showing
12 changed files
with
391 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { CompiledData } from "../../ports/CompileData"; | ||
import type { Db, DbApi } from "../../ports/DbApi"; | ||
|
||
export class InMemoryDbApi implements DbApi { | ||
#softwareRows: Db.SoftwareRow[] = []; | ||
#agentRows: Db.AgentRow[] = []; | ||
#softwareReferentRows: Db.SoftwareReferentRow[] = []; | ||
#softwareUserRows: Db.SoftwareUserRow[] = []; | ||
#instanceRows: Db.InstanceRow[] = []; | ||
|
||
#compiledData: CompiledData<"private"> = []; | ||
|
||
async fetchDb() { | ||
return { | ||
softwareRows: this.#softwareRows, | ||
agentRows: this.#agentRows, | ||
softwareReferentRows: this.#softwareReferentRows, | ||
softwareUserRows: this.#softwareUserRows, | ||
instanceRows: this.#instanceRows | ||
}; | ||
} | ||
|
||
async updateDb({ newDb }: { newDb: Db }) { | ||
this.#softwareRows = newDb.softwareRows; | ||
this.#agentRows = newDb.agentRows; | ||
this.#softwareReferentRows = newDb.softwareReferentRows; | ||
this.#softwareUserRows = newDb.softwareUserRows; | ||
this.#instanceRows = newDb.instanceRows; | ||
} | ||
|
||
async fetchCompiledData() { | ||
return this.#compiledData; | ||
} | ||
|
||
async updateCompiledData({ newCompiledData }: { newCompiledData: CompiledData<"private"> }) { | ||
this.#compiledData = newCompiledData; | ||
} | ||
|
||
// test helpers | ||
|
||
get softwareRows() { | ||
return this.#softwareRows; | ||
} | ||
|
||
get agentRows() { | ||
return this.#agentRows; | ||
} | ||
|
||
get softwareReferentRows() { | ||
return this.#softwareReferentRows; | ||
} | ||
|
||
get softwareUserRows() { | ||
return this.#softwareUserRows; | ||
} | ||
|
||
get instanceRows() { | ||
return this.#instanceRows; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { bootstrapCore } from "../core"; | ||
import { InMemoryDbApi } from "../core/adapters/dbApi/InMemoryDbApi"; | ||
import { ExternalDataOrigin } from "../core/ports/GetSoftwareExternalData"; | ||
import { createRouter } from "./router"; | ||
import { User } from "./user"; | ||
|
||
type TestCallerConfig = { | ||
user: User | undefined; | ||
}; | ||
|
||
export const defaultUser: User = { | ||
id: "1", | ||
email: "[email protected]", | ||
organization: "Default Organization" | ||
}; | ||
|
||
export type ApiCaller = Awaited<ReturnType<typeof createTestCaller>>["apiCaller"]; | ||
|
||
export const createTestCaller = async ({ user }: TestCallerConfig = { user: defaultUser }) => { | ||
const externalSoftwareDataOrigin: ExternalDataOrigin = "wikidata"; | ||
|
||
const { core, context } = await bootstrapCore({ | ||
"dbConfig": { dbKind: "inMemory" }, | ||
"keycloakUserApiParams": undefined, | ||
"githubPersonalAccessTokenForApiRateLimit": "fake-token", | ||
"doPerPerformPeriodicalCompilation": false, | ||
"doPerformCacheInitialization": false, | ||
"externalSoftwareDataOrigin": externalSoftwareDataOrigin | ||
}); | ||
|
||
const jwtClaimByUserKey = { | ||
"id": "sub", | ||
"email": "email", | ||
"organization": "organization" | ||
}; | ||
|
||
const { router } = createRouter({ | ||
core, | ||
coreContext: context, | ||
keycloakParams: undefined, | ||
redirectUrl: undefined, | ||
externalSoftwareDataOrigin, | ||
readmeUrl: "http://readme.url", | ||
termsOfServiceUrl: "http://terms.url", | ||
jwtClaimByUserKey | ||
}); | ||
|
||
return { apiCaller: router.createCaller({ user }), inMemoryDb: context.dbApi as InMemoryDbApi }; | ||
}; |
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
Oops, something went wrong.