@blazetrails/actionmailer 0.0.0-stage → 0.1.0-alpha0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/action-mailer.d.ts +3 -0
- package/dist/action-mailer.js +17 -0
- package/dist/action-mailer.js.map +1 -0
- package/dist/base.d.ts +186 -0
- package/dist/base.js +480 -0
- package/dist/base.js.map +1 -0
- package/dist/callbacks.d.ts +21 -0
- package/dist/callbacks.js +21 -0
- package/dist/callbacks.js.map +1 -0
- package/dist/collector.d.ts +23 -0
- package/dist/collector.js +44 -0
- package/dist/collector.js.map +1 -0
- package/dist/constants.generated.d.ts +2 -0
- package/dist/constants.generated.js +44 -0
- package/dist/constants.generated.js.map +1 -0
- package/dist/constants.test-case.generated.d.ts +2 -0
- package/dist/constants.test-case.generated.js +10 -0
- package/dist/constants.test-case.generated.js.map +1 -0
- package/dist/constants.test-helper.generated.d.ts +2 -0
- package/dist/constants.test-helper.generated.js +4 -0
- package/dist/constants.test-helper.generated.js.map +1 -0
- package/dist/delivery-methods.d.ts +37 -0
- package/dist/delivery-methods.js +79 -0
- package/dist/delivery-methods.js.map +1 -0
- package/dist/deprecator.d.ts +4 -0
- package/dist/deprecator.js +7 -0
- package/dist/deprecator.js.map +1 -0
- package/dist/form-builder.d.ts +17 -0
- package/dist/form-builder.js +18 -0
- package/dist/form-builder.js.map +1 -0
- package/dist/gem-version.d.ts +10 -0
- package/dist/gem-version.js +16 -0
- package/dist/gem-version.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/inline-preview-interceptor.d.ts +21 -0
- package/dist/inline-preview-interceptor.js +49 -0
- package/dist/inline-preview-interceptor.js.map +1 -0
- package/dist/log-subscriber.d.ts +7 -0
- package/dist/log-subscriber.js +36 -0
- package/dist/log-subscriber.js.map +1 -0
- package/dist/mail-delivery-job.d.ts +14 -0
- package/dist/mail-delivery-job.js +46 -0
- package/dist/mail-delivery-job.js.map +1 -0
- package/dist/mail-helper.d.ts +21 -0
- package/dist/mail-helper.js +48 -0
- package/dist/mail-helper.js.map +1 -0
- package/dist/message-delivery.d.ts +38 -0
- package/dist/message-delivery.js +76 -0
- package/dist/message-delivery.js.map +1 -0
- package/dist/namespaces.d.ts +44 -0
- package/dist/namespaces.js +37 -0
- package/dist/namespaces.js.map +1 -0
- package/dist/parameterized.d.ts +42 -0
- package/dist/parameterized.js +93 -0
- package/dist/parameterized.js.map +1 -0
- package/dist/preview.d.ts +48 -0
- package/dist/preview.js +111 -0
- package/dist/preview.js.map +1 -0
- package/dist/queued-delivery.d.ts +2 -0
- package/dist/queued-delivery.js +33 -0
- package/dist/queued-delivery.js.map +1 -0
- package/dist/rescuable.d.ts +15 -0
- package/dist/rescuable.js +32 -0
- package/dist/rescuable.js.map +1 -0
- package/dist/test-case.d.ts +98 -0
- package/dist/test-case.js +124 -0
- package/dist/test-case.js.map +1 -0
- package/dist/test-helper.d.ts +31 -0
- package/dist/test-helper.js +68 -0
- package/dist/test-helper.js.map +1 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.js +5 -0
- package/dist/version.js.map +1 -0
- package/package.json +59 -3
- package/README.md +0 -3
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { TestCase as ActiveSupportTestCase } from "@blazetrails/activesupport/test-case";
|
|
2
|
+
import { type Message } from "@blazetrails/mail";
|
|
3
|
+
import { StandardError } from "@blazetrails/ruby-compat";
|
|
4
|
+
import type { Base } from "./base.js";
|
|
5
|
+
import "./base.js";
|
|
6
|
+
import { TestHelper } from "./test-helper.js";
|
|
7
|
+
import "./constants.test-case.generated.js";
|
|
8
|
+
export declare class NonInferrableMailerError extends StandardError {
|
|
9
|
+
constructor(name: unknown);
|
|
10
|
+
}
|
|
11
|
+
interface BehaviorClass {
|
|
12
|
+
name: string;
|
|
13
|
+
_mailerClass: typeof Base | null;
|
|
14
|
+
setup(...args: unknown[]): void;
|
|
15
|
+
teardown(...args: unknown[]): void;
|
|
16
|
+
tests(mailer: unknown): typeof Base;
|
|
17
|
+
determineDefaultMailer(name: string): typeof Base;
|
|
18
|
+
determineConstantFromTestName(testName: string, block: (constant: unknown) => unknown): unknown;
|
|
19
|
+
}
|
|
20
|
+
/** @internal */
|
|
21
|
+
declare function clearTestDeliveries(): void;
|
|
22
|
+
export declare const ClearTestDeliveries: {
|
|
23
|
+
clearTestDeliveries: typeof clearTestDeliveries;
|
|
24
|
+
};
|
|
25
|
+
export declare const ClassMethods: {
|
|
26
|
+
tests(this: BehaviorClass, mailer: unknown): typeof Base;
|
|
27
|
+
mailerClass(this: BehaviorClass): typeof Base;
|
|
28
|
+
determineDefaultMailer(this: BehaviorClass, name: string): typeof Base;
|
|
29
|
+
};
|
|
30
|
+
export interface Behavior extends Omit<TestHelper, "beforeSetup" | "afterTeardown"> {
|
|
31
|
+
expected: Message;
|
|
32
|
+
_oldPerformDeliveries: boolean;
|
|
33
|
+
_oldDeliveryMethod: unknown;
|
|
34
|
+
readFixture(action: string): Promise<string[]>;
|
|
35
|
+
initializeTestDeliveries(): void;
|
|
36
|
+
restoreTestDeliveries(): void;
|
|
37
|
+
setDeliveryMethod(method: unknown): void;
|
|
38
|
+
restoreDeliveryMethod(): void;
|
|
39
|
+
setExpectedMail(): void;
|
|
40
|
+
charset(): string;
|
|
41
|
+
encode(subject: string): string;
|
|
42
|
+
}
|
|
43
|
+
export declare const Behavior: {
|
|
44
|
+
ClassMethods: {
|
|
45
|
+
tests(this: BehaviorClass, mailer: unknown): typeof Base;
|
|
46
|
+
mailerClass(this: BehaviorClass): typeof Base;
|
|
47
|
+
determineDefaultMailer(this: BehaviorClass, name: string): typeof Base;
|
|
48
|
+
};
|
|
49
|
+
readFixture(this: Behavior, action: string): Promise<string[]>;
|
|
50
|
+
/** @internal */
|
|
51
|
+
initializeTestDeliveries(this: Behavior): void;
|
|
52
|
+
/** @internal */
|
|
53
|
+
restoreTestDeliveries(this: Behavior): void;
|
|
54
|
+
/** @internal */
|
|
55
|
+
setDeliveryMethod(this: Behavior, method: unknown): void;
|
|
56
|
+
/** @internal */
|
|
57
|
+
restoreDeliveryMethod(this: Behavior): void;
|
|
58
|
+
/** @internal */
|
|
59
|
+
setExpectedMail(this: Behavior): void;
|
|
60
|
+
/** @internal */
|
|
61
|
+
charset(): string;
|
|
62
|
+
/** @internal */
|
|
63
|
+
encode(this: Behavior, subject: string): string;
|
|
64
|
+
};
|
|
65
|
+
export interface TestCase extends Behavior {
|
|
66
|
+
}
|
|
67
|
+
export declare class TestCase extends ActiveSupportTestCase {
|
|
68
|
+
static tests: OmitThisParameter<typeof ClassMethods.tests>;
|
|
69
|
+
static mailerClass: OmitThisParameter<typeof ClassMethods.mailerClass>;
|
|
70
|
+
static determineDefaultMailer: OmitThisParameter<typeof ClassMethods.determineDefaultMailer>;
|
|
71
|
+
static ClearTestDeliveries: {
|
|
72
|
+
clearTestDeliveries: typeof clearTestDeliveries;
|
|
73
|
+
};
|
|
74
|
+
static Behavior: {
|
|
75
|
+
ClassMethods: {
|
|
76
|
+
tests(this: BehaviorClass, mailer: unknown): typeof Base;
|
|
77
|
+
mailerClass(this: BehaviorClass): typeof Base;
|
|
78
|
+
determineDefaultMailer(this: BehaviorClass, name: string): typeof Base;
|
|
79
|
+
};
|
|
80
|
+
readFixture(this: Behavior, action: string): Promise<string[]>;
|
|
81
|
+
/** @internal */
|
|
82
|
+
initializeTestDeliveries(this: Behavior): void;
|
|
83
|
+
/** @internal */
|
|
84
|
+
restoreTestDeliveries(this: Behavior): void;
|
|
85
|
+
/** @internal */
|
|
86
|
+
setDeliveryMethod(this: Behavior, method: unknown): void;
|
|
87
|
+
/** @internal */
|
|
88
|
+
restoreDeliveryMethod(this: Behavior): void;
|
|
89
|
+
/** @internal */
|
|
90
|
+
setExpectedMail(this: Behavior): void;
|
|
91
|
+
/** @internal */
|
|
92
|
+
charset(): string;
|
|
93
|
+
/** @internal */
|
|
94
|
+
encode(this: Behavior, subject: string): string;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
export {};
|
|
98
|
+
//# sourceMappingURL=test-case.d.ts.map
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { Concern, camelize, classAttribute, constantize, extend, runLoadHooks, underscore, } from "@blazetrails/activesupport";
|
|
2
|
+
import { ConstantLookup } from "@blazetrails/activesupport/testing/constant-lookup";
|
|
3
|
+
import { TestCase as ActiveSupportTestCase } from "@blazetrails/activesupport/test-case";
|
|
4
|
+
import * as DomAssertions from "@blazetrails/actionview/rails-dom-testing/assertions/dom-assertions";
|
|
5
|
+
import * as SelectorAssertions from "@blazetrails/actionview/rails-dom-testing/assertions/selector-assertions";
|
|
6
|
+
import { Encodings, Mail } from "@blazetrails/mail";
|
|
7
|
+
import { File, IO, StandardError, TopLevel, include, rbModName } from "@blazetrails/ruby-compat";
|
|
8
|
+
import "./base.js";
|
|
9
|
+
import { ActionMailer } from "./namespaces.js";
|
|
10
|
+
import { TestHelper } from "./test-helper.js";
|
|
11
|
+
import "./constants.test-case.generated.js";
|
|
12
|
+
export class NonInferrableMailerError extends StandardError {
|
|
13
|
+
constructor(name) {
|
|
14
|
+
super(`Unable to determine the mailer to test from ${String(name)}. ` +
|
|
15
|
+
"You'll need to specify it using tests YourMailer in your " +
|
|
16
|
+
"test case definition");
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** @internal */
|
|
20
|
+
function clearTestDeliveries() {
|
|
21
|
+
if (ActionMailer.Base.deliveryMethod === "test") {
|
|
22
|
+
ActionMailer.Base.deliveries.length = 0;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export const ClearTestDeliveries = { clearTestDeliveries };
|
|
26
|
+
extend(ClearTestDeliveries, Concern);
|
|
27
|
+
Concern.included.call(ClearTestDeliveries, null, function () {
|
|
28
|
+
this.setup(":clearTestDeliveries");
|
|
29
|
+
this.teardown(":clearTestDeliveries");
|
|
30
|
+
});
|
|
31
|
+
export const ClassMethods = {
|
|
32
|
+
tests(mailer) {
|
|
33
|
+
if (typeof mailer === "string") {
|
|
34
|
+
return (this._mailerClass = constantize(camelize(mailer)));
|
|
35
|
+
}
|
|
36
|
+
else if (typeof mailer === "function") {
|
|
37
|
+
return (this._mailerClass = mailer);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
throw new NonInferrableMailerError(mailer);
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
mailerClass() {
|
|
44
|
+
const mailer = this._mailerClass;
|
|
45
|
+
if (mailer != null) {
|
|
46
|
+
return mailer;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
return this.tests(this.determineDefaultMailer(rbModName(this)));
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
determineDefaultMailer(name) {
|
|
53
|
+
const mailer = this.determineConstantFromTestName(name, (constant) => {
|
|
54
|
+
return typeof constant === "function" && constant.prototype instanceof ActionMailer.Base;
|
|
55
|
+
});
|
|
56
|
+
if (mailer == null)
|
|
57
|
+
throw new NonInferrableMailerError(name);
|
|
58
|
+
return mailer;
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
export const Behavior = {
|
|
62
|
+
ClassMethods,
|
|
63
|
+
async readFixture(action) {
|
|
64
|
+
const klass = this.constructor;
|
|
65
|
+
return await IO.readlinesAsync(File.join(TopLevel.Trails.root(), "test", "fixtures", underscore(rbModName(klass.mailerClass.call(klass))), action));
|
|
66
|
+
},
|
|
67
|
+
/** @internal */
|
|
68
|
+
initializeTestDeliveries() {
|
|
69
|
+
this.setDeliveryMethod("test");
|
|
70
|
+
this._oldPerformDeliveries = ActionMailer.Base.performDeliveries;
|
|
71
|
+
ActionMailer.Base.performDeliveries = true;
|
|
72
|
+
ActionMailer.Base.deliveries.length = 0;
|
|
73
|
+
},
|
|
74
|
+
/** @internal */
|
|
75
|
+
restoreTestDeliveries() {
|
|
76
|
+
this.restoreDeliveryMethod();
|
|
77
|
+
ActionMailer.Base.performDeliveries = this._oldPerformDeliveries;
|
|
78
|
+
},
|
|
79
|
+
/** @internal */
|
|
80
|
+
setDeliveryMethod(method) {
|
|
81
|
+
this._oldDeliveryMethod = ActionMailer.Base.deliveryMethod;
|
|
82
|
+
ActionMailer.Base.deliveryMethod = method;
|
|
83
|
+
},
|
|
84
|
+
/** @internal */
|
|
85
|
+
restoreDeliveryMethod() {
|
|
86
|
+
ActionMailer.Base.deliveries.length = 0;
|
|
87
|
+
ActionMailer.Base.deliveryMethod = this._oldDeliveryMethod;
|
|
88
|
+
},
|
|
89
|
+
/** @internal */
|
|
90
|
+
setExpectedMail() {
|
|
91
|
+
this.expected = Mail.new();
|
|
92
|
+
this.expected.contentType(["text", "plain", { charset: this.charset() }]);
|
|
93
|
+
this.expected.setMimeVersion("1.0");
|
|
94
|
+
},
|
|
95
|
+
/** @internal */
|
|
96
|
+
charset() {
|
|
97
|
+
return "UTF-8";
|
|
98
|
+
},
|
|
99
|
+
/** @internal */
|
|
100
|
+
encode(subject) {
|
|
101
|
+
return Encodings.qValueEncode(subject, this.charset());
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
extend(Behavior, Concern);
|
|
105
|
+
include(Behavior, ConstantLookup);
|
|
106
|
+
include(Behavior, TestHelper);
|
|
107
|
+
include(Behavior, SelectorAssertions);
|
|
108
|
+
include(Behavior, DomAssertions);
|
|
109
|
+
Concern.included.call(Behavior, null, function () {
|
|
110
|
+
classAttribute.call(this, "_mailerClass", { default: null });
|
|
111
|
+
this.setup(":initializeTestDeliveries");
|
|
112
|
+
this.setup(":setExpectedMail");
|
|
113
|
+
this.teardown(":restoreTestDeliveries");
|
|
114
|
+
runLoadHooks("action_mailer_test_case", this);
|
|
115
|
+
});
|
|
116
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging -- see the interface above.
|
|
117
|
+
export class TestCase extends ActiveSupportTestCase {
|
|
118
|
+
static ClearTestDeliveries = ClearTestDeliveries;
|
|
119
|
+
static Behavior = Behavior;
|
|
120
|
+
}
|
|
121
|
+
include(TestCase, Behavior);
|
|
122
|
+
ActionMailer.TestCase = TestCase;
|
|
123
|
+
ActionMailer.NonInferrableMailerError = NonInferrableMailerError;
|
|
124
|
+
//# sourceMappingURL=test-case.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-case.js","sourceRoot":"","sources":["../lib/test-case.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,QAAQ,EACR,cAAc,EACd,WAAW,EACX,MAAM,EACN,YAAY,EACZ,UAAU,GACX,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,oDAAoD,CAAC;AACpF,OAAO,EAAE,QAAQ,IAAI,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AACzF,OAAO,KAAK,aAAa,MAAM,qEAAqE,CAAC;AACrG,OAAO,KAAK,kBAAkB,MAAM,0EAA0E,CAAC;AAC/G,OAAO,EAAE,SAAS,EAAE,IAAI,EAAgB,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,aAAa,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAEjG,OAAO,WAAW,CAAC;AACnB,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,oCAAoC,CAAC;AAE5C,MAAM,OAAO,wBAAyB,SAAQ,aAAa;IACzD,YAAY,IAAa;QACvB,KAAK,CACH,+CAA+C,MAAM,CAAC,IAAI,CAAC,IAAI;YAC7D,2DAA2D;YAC3D,sBAAsB,CACzB,CAAC;IACJ,CAAC;CACF;AAYD,gBAAgB;AAChB,SAAS,mBAAmB;IAC1B,IAAI,YAAY,CAAC,IAAI,CAAC,cAAc,KAAK,MAAM,EAAE,CAAC;QAChD,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC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;IACxC,YAAY,CAAC,yBAAyB,EAAE,IAAI,CAAC,CAAC;AAChD,CAAC,CAAC,CAAC;AAKH,wGAAwG;AACxG,MAAM,OAAO,QAAS,SAAQ,qBAAqB;IAOjD,MAAM,CAAC,mBAAmB,GAAG,mBAAmB,CAAC;IACjD,MAAM,CAAC,QAAQ,GAAG,QAAQ,CAAC;CAC5B;AACD,OAAO,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAE5B,YAAY,CAAC,QAAQ,GAAG,QAAQ,CAAC;AACjC,YAAY,CAAC,wBAAwB,GAAG,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import "./constants.test-helper.generated.js";
|
|
2
|
+
import { TestHelper as ActiveJobTestHelper } from "@blazetrails/activejob/test-helper";
|
|
3
|
+
import type { Message } from "@blazetrails/mail";
|
|
4
|
+
import "./base.js";
|
|
5
|
+
type Block = (() => unknown) | null;
|
|
6
|
+
interface AssertEnqueuedEmailWithOptions {
|
|
7
|
+
params?: unknown;
|
|
8
|
+
args?: unknown;
|
|
9
|
+
queue?: unknown;
|
|
10
|
+
}
|
|
11
|
+
interface DeliverEnqueuedEmailsOptions {
|
|
12
|
+
queue?: unknown;
|
|
13
|
+
at?: unknown;
|
|
14
|
+
}
|
|
15
|
+
export declare const TestHelper: {
|
|
16
|
+
assertEmails(this: TestHelper, number: number, block?: Block): Promise<void>;
|
|
17
|
+
assertNoEmails(this: TestHelper, block?: Block): Promise<void>;
|
|
18
|
+
assertEnqueuedEmails(this: TestHelper, number: number, block?: Block): Promise<void>;
|
|
19
|
+
assertEnqueuedEmailWith(this: TestHelper, mailer: unknown, method: string, { params, args, queue }?: AssertEnqueuedEmailWithOptions, block?: Block): Promise<unknown>;
|
|
20
|
+
assertNoEnqueuedEmails(this: TestHelper, block?: Block): Promise<void>;
|
|
21
|
+
deliverEnqueuedEmails(this: TestHelper, { queue, at }?: DeliverEnqueuedEmailsOptions, block?: Block): Promise<unknown>;
|
|
22
|
+
captureEmails(this: TestHelper, block?: Block): Promise<Message[]>;
|
|
23
|
+
/** @internal */
|
|
24
|
+
deliveryJobFilter(this: TestHelper, job: unknown): boolean;
|
|
25
|
+
};
|
|
26
|
+
export interface TestHelper extends ActiveJobTestHelper, Omit<typeof TestHelper, "deliveryJobFilter"> {
|
|
27
|
+
/** @internal */
|
|
28
|
+
deliveryJobFilter(job: unknown): boolean;
|
|
29
|
+
}
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=test-helper.d.ts.map
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import "./constants.test-helper.generated.js";
|
|
2
|
+
import { Base as ActiveJobBase } from "@blazetrails/activejob";
|
|
3
|
+
import { TestHelper as ActiveJobTestHelper } from "@blazetrails/activejob/test-helper";
|
|
4
|
+
import { extractOptionsBang, kernelArray } from "@blazetrails/activesupport";
|
|
5
|
+
import { assertEqual } from "@blazetrails/activesupport/testing/assertions";
|
|
6
|
+
import { fetch, include, isPlainHash, rbEqq, rbEqual, rbModName, rbObjClass, rbObjIsProc, } from "@blazetrails/ruby-compat";
|
|
7
|
+
import "./base.js";
|
|
8
|
+
import { ActionMailer } from "./namespaces.js";
|
|
9
|
+
import { Mailer as ParameterizedMailer } from "./parameterized.js";
|
|
10
|
+
export const TestHelper = {
|
|
11
|
+
async assertEmails(number, block = null) {
|
|
12
|
+
if (block != null) {
|
|
13
|
+
const diff = (await this.captureEmails(block)).length;
|
|
14
|
+
assertEqual(number, diff, `${number} emails expected, but ${diff} were sent`);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
assertEqual(number, ActionMailer.Base.deliveries.length);
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
async assertNoEmails(block = null) {
|
|
21
|
+
await this.assertEmails(0, block);
|
|
22
|
+
},
|
|
23
|
+
async assertEnqueuedEmails(number, block = null) {
|
|
24
|
+
const only = (job) => this.deliveryJobFilter(job);
|
|
25
|
+
await this.assertEnqueuedJobs(number, { only }, block);
|
|
26
|
+
},
|
|
27
|
+
async assertEnqueuedEmailWith(mailer, method, { params = null, args = null, queue = null } = {}, block = null) {
|
|
28
|
+
if (mailer instanceof ParameterizedMailer) {
|
|
29
|
+
params = mailer._params;
|
|
30
|
+
mailer = mailer._mailer;
|
|
31
|
+
}
|
|
32
|
+
if (!rbObjIsProc(args))
|
|
33
|
+
args = kernelArray(args);
|
|
34
|
+
const mailerClass = mailer;
|
|
35
|
+
queue ??= mailerClass.deliverLaterQueueName ?? ActiveJobBase.defaultQueueName;
|
|
36
|
+
const expected = (jobArgs) => {
|
|
37
|
+
const jobKwargs = extractOptionsBang(jobArgs);
|
|
38
|
+
return (rbEqual([rbModName(mailerClass), String(method), "deliverNow"], jobArgs) &&
|
|
39
|
+
rbEqq(params, jobKwargs.params ?? null) &&
|
|
40
|
+
rbEqq(args, jobKwargs.args ?? null));
|
|
41
|
+
};
|
|
42
|
+
return await this.assertEnqueuedWith({ job: mailerClass.deliveryJob, args: expected, queue: String(queue) }, block);
|
|
43
|
+
},
|
|
44
|
+
async assertNoEnqueuedEmails(block = null) {
|
|
45
|
+
await this.assertEnqueuedEmails(0, block);
|
|
46
|
+
},
|
|
47
|
+
async deliverEnqueuedEmails({ queue = null, at = null } = {}, block = null) {
|
|
48
|
+
const only = (job) => this.deliveryJobFilter(job);
|
|
49
|
+
return await this.performEnqueuedJobs({ only, queue, at }, block);
|
|
50
|
+
},
|
|
51
|
+
async captureEmails(block = null) {
|
|
52
|
+
const originalCount = ActionMailer.Base.deliveries.length;
|
|
53
|
+
await this.deliverEnqueuedEmails({}, block);
|
|
54
|
+
const newCount = ActionMailer.Base.deliveries.length;
|
|
55
|
+
const diff = newCount - originalCount;
|
|
56
|
+
return ActionMailer.Base.deliveries.slice(newCount - diff);
|
|
57
|
+
},
|
|
58
|
+
/** @internal */
|
|
59
|
+
deliveryJobFilter(job) {
|
|
60
|
+
const jobClass = isPlainHash(job) ? fetch(job, "job") : rbObjClass(job);
|
|
61
|
+
return ActionMailer.Base.descendants
|
|
62
|
+
.map((klass) => klass.deliveryJob)
|
|
63
|
+
.includes(jobClass);
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
include(TestHelper, ActiveJobTestHelper);
|
|
67
|
+
ActionMailer.TestHelper = TestHelper;
|
|
68
|
+
//# sourceMappingURL=test-helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-helper.js","sourceRoot":"","sources":["../lib/test-helper.ts"],"names":[],"mappings":"AAAA,OAAO,sCAAsC,CAAC;AAC9C,OAAO,EAAE,IAAI,IAAI,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,UAAU,IAAI,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACvF,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC7E,OAAO,EAAE,WAAW,EAAE,MAAM,+CAA+C,CAAC;AAE5E,OAAO,EACL,KAAK,EACL,OAAO,EACP,WAAW,EACX,KAAK,EACL,OAAO,EACP,SAAS,EACT,UAAU,EACV,WAAW,GACZ,MAAM,0BAA0B,CAAC;AAElC,OAAO,WAAW,CAAC;AACnB,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,MAAM,IAAI,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAenE,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,KAAK,CAAC,YAAY,CAAmB,MAAc,EAAE,KAAK,GAAU,IAAI;QACtE,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;YAClB,MAAM,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC;YACtD,WAAW,CAAC,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,yBAAyB,IAAI,YAAY,CAAC,CAAC;QAChF,CAAC;aAAM,CAAC;YACN,WAAW,CAAC,MAAM,EAAE,YAA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D,CAAC;IAED,gBAAgB;IAChB,iBAAiB,CAAmB,GAAY;QAC9C,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QAExE,OAAO,YAAY,CAAC,IAAI,CAAC,WAAW;aACjC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,WAAW,CAAC;aACjC,QAAQ,CAAC,QAAmC,CAAC,CAAC;IACnD,CAAC;CACF,CAAC;AAMF,OAAO,CAAC,UAAU,EAAE,mBAAmB,CAAC,CAAC;AACzC,YAAY,CAAC,UAAU,GAAG,UAAU,CAAC"}
|
package/dist/version.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../lib/version.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,MAAM,UAAU,OAAO;IACrB,OAAO,UAAU,EAAE,CAAC;AACtB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,62 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blazetrails/actionmailer",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0-alpha0.1",
|
|
4
|
+
"description": "Email composition and delivery for Trails, mirroring the actionmailer gem",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"url": "git+https://github.com/blazetrailsdev/trails.git",
|
|
8
|
+
"directory": "packages/actionmailer"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/blazetrailsdev/trails/tree/main/packages/actionmailer#readme",
|
|
11
|
+
"type": "module",
|
|
12
|
+
"main": "dist/index.js",
|
|
13
|
+
"types": "dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./*.js": {
|
|
20
|
+
"types": "./dist/*.d.ts",
|
|
21
|
+
"default": "./dist/*.js"
|
|
22
|
+
},
|
|
23
|
+
"./*": {
|
|
24
|
+
"types": "./dist/*.d.ts",
|
|
25
|
+
"default": "./dist/*.js"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist",
|
|
30
|
+
"!dist/**/*.d.ts.map"
|
|
31
|
+
],
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@blazetrails/actionpack": "0.1.0-alpha0.1",
|
|
34
|
+
"@blazetrails/actionview": "0.1.0-alpha0.1",
|
|
35
|
+
"@blazetrails/activejob": "0.1.0-alpha0.1",
|
|
36
|
+
"@blazetrails/activesupport": "0.1.0-alpha0.1",
|
|
37
|
+
"@blazetrails/date": "0.1.0-alpha0.1",
|
|
38
|
+
"@blazetrails/i18n": "0.1.0-alpha0.1",
|
|
39
|
+
"@blazetrails/mail": "0.1.0-alpha0.1",
|
|
40
|
+
"@blazetrails/ruby-compat": "0.1.0-alpha0.1"
|
|
41
|
+
},
|
|
42
|
+
"engines": {
|
|
43
|
+
"node": ">=26"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@blazetrails/globalid": "0.1.0-alpha0.1",
|
|
47
|
+
"@blazetrails/vitest-matchers": "0.1.0-alpha0.1"
|
|
48
|
+
},
|
|
49
|
+
"mirrors": [
|
|
50
|
+
{
|
|
51
|
+
"source": "rails",
|
|
52
|
+
"ref": "v8.0.5.2",
|
|
53
|
+
"sha": "235c597b100321b6bd2d62f8df63707f42b25b2d"
|
|
54
|
+
}
|
|
55
|
+
],
|
|
56
|
+
"publishConfig": {
|
|
57
|
+
"access": "public"
|
|
58
|
+
},
|
|
59
|
+
"scripts": {
|
|
60
|
+
"build": "tsc"
|
|
61
|
+
}
|
|
6
62
|
}
|
package/README.md
DELETED