Skip to content

Commit

Permalink
Feature: logging wrapper tests (#157)
Browse files Browse the repository at this point in the history
* feature(logging-wrapper): added tests helper

* Added README for logging-wrapper

* Added tap

* Added gitignore

* Tap config

* Added tests for logging-wrapper.test.ts

* Added fastify tests

* Chore: Use logging-wrapper in payments-api (#160)

* Updated wrapper to be built

* Updated commands to build logging wrapper

* Removed useless files

* Payments api is using logging wrapper

* Updated error response management

* Updated version

* Fixed logging wrapper tests

* Updated packages

* Copy logging wrapper in the dockerfile

* Added error handling package

* Added package script

* Optional logging hooks

* Removed logging hooks

* Started working on error handling tests

* Started working on error handling tests

* Added tests for not found handler

* Added logging hooks

* Removed useless copy

* Renamed to error-handler

* Updated sdk definitions
  • Loading branch information
SamSalvatico authored Apr 29, 2024
1 parent 40c8830 commit 81ac256
Show file tree
Hide file tree
Showing 35 changed files with 5,847 additions and 2,909 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ function assignTemplateLiterals(set: Set<string>, s?: string) {
scpy = tmpl ? scpy.slice(scpy.indexOf(tmpl) + tmpl.length) : "";
current = xp.exec(scpy);
}

}

export default async (props: {
Expand Down
24 changes: 4 additions & 20 deletions apps/payments-api/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import { dirname, join } from "path";
import healthCheck from "./routes/healthcheck";
import sensible from "@fastify/sensible";
import schemaValidators from "./routes/schemas/validations";
import { STATUS_CODES } from "http";
import { initializeErrorHandler } from "error-handler";
import { initializeLoggingHooks } from "logging-wrapper";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
Expand All @@ -23,6 +24,8 @@ dotenv.config();

export async function build(opts?: FastifyServerOptions) {
const app = fastify(opts).withTypeProvider<TypeBoxTypeProvider>();
initializeLoggingHooks(app);
initializeErrorHandler(app);

app.setValidatorCompiler(({ schema }) => {
return schemaValidators(schema);
Expand Down Expand Up @@ -74,24 +77,5 @@ export async function build(opts?: FastifyServerOptions) {

app.register(sensible);

app.setErrorHandler((error, request, reply) => {
app.log.error(error);
if (
error instanceof Error &&
(error.name !== "error" || !!error.validation)
) {
reply.status(error.statusCode || 500).send({
error: STATUS_CODES[error.statusCode || 500],
message: error.message,
name: error.name,
validation: error.validation,
validationContext: error.validationContext,
statusCode: error.statusCode || 500,
});
return;
}
reply.code(500).type("application/json").send({ error });
});

return app;
}
4 changes: 2 additions & 2 deletions apps/payments-api/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { writeFile } from "fs/promises";

import { getLoggingConfiguration } from "logging-wrapper";
import { build } from "./app";

const app = await build({ logger: true });
const app = await build(getLoggingConfiguration());

app.listen({ host: "0.0.0.0", port: 8001 }, (err, address) => {
if (err) {
Expand Down
4 changes: 4 additions & 0 deletions apps/payments-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
"../../packages/auth/src/**/*",
"../../packages/feature-flags/src/**/*",
"../../packages/messages/src/**/*",
"../../packages/logging-wrapper/src/**/*",
"../../packages/error-handler/src/**/*",
"./**/*"
],
"ext": "ts,json",
Expand All @@ -39,6 +41,8 @@
"dotenv": "^16.4.5",
"fastify": "^4.26.2",
"fastify-plugin": "^4.5.1",
"logging-wrapper": "*",
"error-handler": "*",
"pg": "^8.11.3"
},
"devDependencies": {
Expand Down
2 changes: 0 additions & 2 deletions apps/payments/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ COPY ./packages/feature-flags/package*.json /app/packages/feature-flags/
COPY ./packages/auth/package*.json /app/packages/auth/
COPY ./packages/building-blocks-sdk/package*.json /app/packages/building-blocks-sdk/


RUN npm ci

COPY ./apps/payments/ /app/apps/payments/
Expand All @@ -19,7 +18,6 @@ COPY ./packages/feature-flags/ /app/packages/feature-flags/
COPY ./packages/auth/ /app/packages/auth/
COPY ./packages/building-blocks-sdk/ /app/packages/building-blocks-sdk/


FROM deps AS builder
WORKDIR /app
ARG NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY
Expand Down
Loading

0 comments on commit 81ac256

Please sign in to comment.