Skip to content

Commit

Permalink
Fix integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastijankuzner committed Feb 29, 2024
1 parent 11c48ce commit f559e29
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions packages/api-http/test/helpers/prepare-sandbox.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Identifiers } from "@mainsail/contracts";
import { Providers, Application } from "@mainsail/kernel";
import { Application, Providers } from "@mainsail/kernel";

import {
ServiceProvider as CoreApiDatabase,
Contracts as ApiDatabaseContracts,
Identifiers as ApiDatabaseIdentifiers,
ServiceProvider as CoreApiDatabase,
} from "../../../api-database";
import { ServiceProvider as CoreApiHttp } from "../../../api-http";
import { Sandbox } from "../../../test-framework";
import { Validator } from "../../../validation/source/validator";
import { ServiceProvider as CoreApiHttp } from "../..";

export class ApiContext {
public constructor(
Expand Down Expand Up @@ -99,10 +100,13 @@ export const prepareSandbox = async (context: { sandbox: Sandbox }): Promise<Api
.to(Providers.PluginConfiguration)
.inSingletonScope();

context.sandbox.app.bind(Identifiers.Services.EventDispatcher.Service).toConstantValue({});
context.sandbox.app.bind(Identifiers.Cryptography.Validator).to(Validator).inSingletonScope();

context.sandbox.app.bind(Identifiers.Services.Log.Service).toConstantValue({
info: (msg) => console.log(msg),
notice: (msg) => console.log(msg),
error: (msg) => console.log(msg),
error: (message) => console.log(message),
info: (message) => console.log(message),
notice: (message) => console.log(message),
});

const apiDatabase = await setupDatabase(context.sandbox.app);
Expand All @@ -119,10 +123,10 @@ const setupDatabase = async (app: Application): Promise<CoreApiDatabase> => {
database: {
...databaseOptions,
applicationName: "mainsail/api-database-test",
migrationsRun: true,
dropSchema: true,
synchronize: true,
logging: false,
migrationsRun: true,
synchronize: true,
},
});

Expand All @@ -138,17 +142,17 @@ const setupHttp = async (app: Application): Promise<CoreApiHttp> => {
.get<Providers.PluginConfiguration>(Identifiers.ServiceProvider.Configuration)
.discover("@mainsail/api-http", "@mainsail/api-http")
.merge({
server: { http: { enabled: true, host: "127.0.0.1", port: 4003 } },
database: {
...databaseOptions,
applicationName: "mainsail/api-http-test",
},
plugins: {
pagination: {
limit: 100,
},
socketTimeout: 5000,
},
database: {
...databaseOptions,
applicationName: "mainsail/api-http-test",
},
server: { http: { enabled: true, host: "127.0.0.1", port: 4003 } },
});

const server = app.resolve(CoreApiHttp);
Expand All @@ -161,16 +165,16 @@ const setupHttp = async (app: Application): Promise<CoreApiHttp> => {

// TODO: either use env or hardcode same values for postgres in CI
const databaseOptions = {
type: "postgres",
database: "test_db",
username: "test_db",
dropSchema: false,
entityPrefix: "public.",
password: "password",
host: "localhost",
port: 5432,
logger: "simple-console",
logging: false,
migrationsRun: false,
dropSchema: false,
password: "password",
port: 5432,
synchronize: false,
logging: false,
type: "postgres",
username: "test_db",
};

0 comments on commit f559e29

Please sign in to comment.