Skip to content

Commit

Permalink
chore: snapshot of done work
Browse files Browse the repository at this point in the history
  • Loading branch information
Fifciu committed Oct 15, 2024
1 parent 442d530 commit d56c6b1
Show file tree
Hide file tree
Showing 12 changed files with 696 additions and 43 deletions.
6 changes: 5 additions & 1 deletion packages/logger/src/interfaces/LoggerInterface.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
/**
* Metadata is a record with string keys and arbitrary values.
*/
export type Metadata = Record<string, unknown>;
export type Metadata = {
[key: string]: any;
troubleshoot?: Record<string, any> | string[];
alokai?: never;
};

/**
* Log data can be a string, an error, or and arbitrary object.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export const success = () => {
import { getLogger } from "../../../../../src";

export const success = (context) => {
const logger = getLogger(context);
logger.info("success");
return Promise.resolve({
status: 200,
message: "ok",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { apiClientFactory } from "../../../src/apiClientFactory";
import * as api from "./api";
import { AlokaiContainer, getLogger } from "../../../src";

const onCreate = async (
config: Record<string, unknown> = {},
alokai: AlokaiContainer
) => {
const logger = getLogger(alokai);
logger.info("oncreate");

const onCreate = async (config: Record<string, unknown> = {}) => {
return {
config,
client: null,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { apiClientFactory } from "../../../src/apiClientFactory";
import * as api from "./api";
import { AlokaiContainer, getLogger } from "../../../src";

const init = (settings: any, alokai: AlokaiContainer) => {
const logger = getLogger(alokai);
logger.info("Init fn!");
return {
config: settings,
client: null,
};
};

const onCreate = async (
config: Record<string, unknown> = {},
alokai: AlokaiContainer
) => {
const logger = getLogger(alokai);
logger.info("oncreate");

return {
config,
client: null,
};
};

const { createApiClient } = apiClientFactory({
onCreate,
api,
});

export { createApiClient, init };
31 changes: 28 additions & 3 deletions packages/middleware/__tests__/integration/createServer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import request from "supertest";
import { Server } from "http";
import { createServer } from "../../src/index";
import { success } from "./bootstrap/api";
import { logger } from "../../__mocks__/logger";

describe("[Integration] Create server", () => {
let app: Server;
Expand Down Expand Up @@ -109,7 +110,15 @@ describe("[Integration] Create server", () => {
const response = JSON.parse(text);

// This is the result of the original "success" function from the integration
const apiMethodResult = await success();
const apiMethodResult = await success({
res: {
locals: {
alokai: {
logger,
},
},
},
} as any);

expect(status).toEqual(200);
expect(response).toEqual(apiMethodResult);
Expand Down Expand Up @@ -161,7 +170,15 @@ describe("[Integration] Create server", () => {

const response = JSON.parse(text);
// This is the result of the original "success" function from the integration
const apiMethodResult = await success();
const apiMethodResult = await success({
res: {
locals: {
alokai: {
logger,
},
},
},
} as any);

expect(status).toEqual(200);
expect(response).toEqual(apiMethodResult);
Expand Down Expand Up @@ -202,7 +219,15 @@ describe("[Integration] Create server", () => {

const response = JSON.parse(text);
// This is the result of the original "success" function from the integration
const apiMethodResult = await success();
const apiMethodResult = await success({
res: {
locals: {
alokai: {
logger,
},
},
},
} as any);

// If merged, the response would be { message: "error", error: true, status: 404 }
expect(status).toEqual(200);
Expand Down
Loading

0 comments on commit d56c6b1

Please sign in to comment.