Skip to content

Commit d56c6b1

Browse files
committed
chore: snapshot of done work
1 parent 442d530 commit d56c6b1

File tree

12 files changed

+696
-43
lines changed

12 files changed

+696
-43
lines changed

packages/logger/src/interfaces/LoggerInterface.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
/**
22
* Metadata is a record with string keys and arbitrary values.
33
*/
4-
export type Metadata = Record<string, unknown>;
4+
export type Metadata = {
5+
[key: string]: any;
6+
troubleshoot?: Record<string, any> | string[];
7+
alokai?: never;
8+
};
59

610
/**
711
* Log data can be a string, an error, or and arbitrary object.

packages/middleware/__tests__/integration/bootstrap/api/success/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
export const success = () => {
1+
import { getLogger } from "../../../../../src";
2+
3+
export const success = (context) => {
4+
const logger = getLogger(context);
5+
logger.info("success");
26
return Promise.resolve({
37
status: 200,
48
message: "ok",

packages/middleware/__tests__/integration/bootstrap/server.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import { apiClientFactory } from "../../../src/apiClientFactory";
22
import * as api from "./api";
3+
import { AlokaiContainer, getLogger } from "../../../src";
4+
5+
const onCreate = async (
6+
config: Record<string, unknown> = {},
7+
alokai: AlokaiContainer
8+
) => {
9+
const logger = getLogger(alokai);
10+
logger.info("oncreate");
311

4-
const onCreate = async (config: Record<string, unknown> = {}) => {
512
return {
613
config,
714
client: null,
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { apiClientFactory } from "../../../src/apiClientFactory";
2+
import * as api from "./api";
3+
import { AlokaiContainer, getLogger } from "../../../src";
4+
5+
const init = (settings: any, alokai: AlokaiContainer) => {
6+
const logger = getLogger(alokai);
7+
logger.info("Init fn!");
8+
return {
9+
config: settings,
10+
client: null,
11+
};
12+
};
13+
14+
const onCreate = async (
15+
config: Record<string, unknown> = {},
16+
alokai: AlokaiContainer
17+
) => {
18+
const logger = getLogger(alokai);
19+
logger.info("oncreate");
20+
21+
return {
22+
config,
23+
client: null,
24+
};
25+
};
26+
27+
const { createApiClient } = apiClientFactory({
28+
onCreate,
29+
api,
30+
});
31+
32+
export { createApiClient, init };

packages/middleware/__tests__/integration/createServer.spec.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import request from "supertest";
22
import { Server } from "http";
33
import { createServer } from "../../src/index";
44
import { success } from "./bootstrap/api";
5+
import { logger } from "../../__mocks__/logger";
56

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

111112
// This is the result of the original "success" function from the integration
112-
const apiMethodResult = await success();
113+
const apiMethodResult = await success({
114+
res: {
115+
locals: {
116+
alokai: {
117+
logger,
118+
},
119+
},
120+
},
121+
} as any);
113122

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

162171
const response = JSON.parse(text);
163172
// This is the result of the original "success" function from the integration
164-
const apiMethodResult = await success();
173+
const apiMethodResult = await success({
174+
res: {
175+
locals: {
176+
alokai: {
177+
logger,
178+
},
179+
},
180+
},
181+
} as any);
165182

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

203220
const response = JSON.parse(text);
204221
// This is the result of the original "success" function from the integration
205-
const apiMethodResult = await success();
222+
const apiMethodResult = await success({
223+
res: {
224+
locals: {
225+
alokai: {
226+
logger,
227+
},
228+
},
229+
},
230+
} as any);
206231

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

0 commit comments

Comments
 (0)