Skip to content

Commit bd800d6

Browse files
adrians5jclaude
andauthored
refactor(api-mailer): remove ContextPlugin from tests (#5423)
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 06061af commit bd800d6

8 files changed

Lines changed: 21 additions & 21 deletions

File tree

packages/api-mailer/__tests__/contextHandler.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,13 @@ export const createContextHandler = (params?: CreateHandlerParams) => {
6262

6363
const ctx: Record<string, any> = { container: child };
6464

65-
// Apply additional plugins (e.g. registerCodeSmtpSettings)
65+
// Apply additional plugins (e.g. registerCodeSmtpSettings). DI-native plugins are plain
66+
// `container => {}` functions; legacy ContextPlugins expose `apply(ctx)`.
6667
const additionalPlugins = [params?.plugins ?? []].flat(Infinity as 1).filter(Boolean);
6768
for (const plugin of additionalPlugins as any[]) {
68-
if (typeof plugin.apply === "function") {
69+
if (typeof plugin === "function" && !plugin.prototype) {
70+
plugin(child);
71+
} else if (typeof plugin.apply === "function") {
6972
await plugin.apply(ctx);
7073
}
7174
}

packages/api-mailer/__tests__/graphQLHandler.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,16 @@ export const createGraphQLHandler = (params?: CreateHandlerParams) => {
6262
GraphQLEngineFeature.register(container);
6363
MailerFeature.register(container);
6464

65-
// Apply additional plugins (e.g. registerCodeSmtpSettings)
65+
// Apply additional plugins (e.g. registerCodeSmtpSettings). DI-native plugins are plain
66+
// `container => {}` functions; legacy ContextPlugins expose a custom `apply(ctx)`. Check
67+
// for a function FIRST — a plain function also has `Function.prototype.apply`, which would
68+
// otherwise be invoked with no args (container undefined).
6669
const additionalPlugins = [params?.plugins ?? []].flat(Infinity as 1).filter(Boolean);
6770
const ctx: Record<string, any> = { container };
6871
for (const plugin of additionalPlugins as any[]) {
69-
if (typeof plugin.apply === "function") {
72+
if (typeof plugin === "function" && !plugin.prototype) {
73+
plugin(container);
74+
} else if (typeof plugin.apply === "function") {
7075
await plugin.apply(ctx);
7176
}
7277
}

packages/api-mailer/__tests__/helpers/registerCodeSmtpSettings.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createContextPlugin } from "@webiny/api";
1+
import type { Container } from "@webiny/di";
22
import { BuildParam } from "@webiny/api-core/features/buildParams/index.js";
33
import type { TransportSettings } from "~/types.js";
44

@@ -13,7 +13,7 @@ export const registerCodeSmtpSettings = (settings: TransportSettings) => {
1313
dependencies: []
1414
});
1515

16-
return createContextPlugin(context => {
17-
context.container.register(implementation);
18-
});
16+
return (container: Container) => {
17+
container.register(implementation);
18+
};
1919
};

packages/api-mailer/__tests__/saveSettingsEvents.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, it, expect, beforeEach } from "vitest";
2-
import { createContextPlugin } from "@webiny/api";
2+
import type { Container } from "@webiny/di";
33
import { createContextHandler } from "./contextHandler";
44
import {
55
SaveSettingsUseCase,
@@ -41,10 +41,10 @@ const AfterCaptureImpl = MailerSettingsAfterSaveEventHandler.createImplementatio
4141
dependencies: []
4242
});
4343

44-
const registerCapturePlugin = createContextPlugin(ctx => {
45-
ctx.container.register(BeforeCaptureImpl);
46-
ctx.container.register(AfterCaptureImpl);
47-
});
44+
const registerCapturePlugin = (container: Container) => {
45+
container.register(BeforeCaptureImpl);
46+
container.register(AfterCaptureImpl);
47+
};
4848

4949
const input = {
5050
host: "dummy.webiny",

packages/api-mailer/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"description": "The API to send e-mails.",
1919
"license": "MIT",
2020
"dependencies": {
21-
"@webiny/api": "0.0.0",
2221
"@webiny/feature": "0.0.0",
2322
"@webiny/handler-graphql": "0.0.0",
2423
"@webiny/plugins": "0.0.0",

packages/api-mailer/tsconfig.build.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"extends": "../../tsconfig.build.json",
33
"include": ["src"],
44
"references": [
5-
{ "path": "../api/tsconfig.build.json" },
65
{ "path": "../feature/tsconfig.build.json" },
76
{ "path": "../handler-graphql/tsconfig.build.json" },
87
{ "path": "../plugins/tsconfig.build.json" },
@@ -18,8 +17,6 @@
1817
"paths": {
1918
"~/*": ["./src/*"],
2019
"~tests/*": ["./__tests__/*"],
21-
"@webiny/api/*": ["../api/src/*"],
22-
"@webiny/api": ["../api/src"],
2320
"@webiny/feature/*": ["../feature/src/*"],
2421
"@webiny/feature": ["../feature/src"],
2522
"@webiny/handler-graphql/*": ["../handler-graphql/src/*"],

packages/api-mailer/tsconfig.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"extends": "../../tsconfig.json",
33
"include": ["src", "__tests__"],
44
"references": [
5-
{ "path": "../api" },
65
{ "path": "../feature" },
76
{ "path": "../handler-graphql" },
87
{ "path": "../plugins" },
@@ -18,8 +17,6 @@
1817
"paths": {
1918
"~/*": ["./src/*"],
2019
"~tests/*": ["./__tests__/*"],
21-
"@webiny/api/*": ["../api/src/*"],
22-
"@webiny/api": ["../api/src"],
2320
"@webiny/feature/*": ["../feature/src/*"],
2421
"@webiny/feature": ["../feature/src"],
2522
"@webiny/handler-graphql/*": ["../handler-graphql/src/*"],

yarn.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11309,7 +11309,6 @@ __metadata:
1130911309
resolution: "@webiny/api-mailer@workspace:packages/api-mailer"
1131011310
dependencies:
1131111311
"@types/nodemailer": "npm:^8.0.1"
11312-
"@webiny/api": "npm:0.0.0"
1131311312
"@webiny/api-core": "npm:0.0.0"
1131411313
"@webiny/build-tools": "npm:0.0.0"
1131511314
"@webiny/di": "npm:^1.0.2"

0 commit comments

Comments
 (0)