@bernierllc/email-campaign-management 1.3.1 → 1.5.0
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/dist/api/client.js +1 -0
- package/dist/errors.d.ts +11 -0
- package/dist/errors.js +27 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/package.json +8 -4
- package/.eslintrc.cjs +0 -45
- package/CHANGELOG.md +0 -160
- package/__tests__/api/campaigns.test.ts +0 -217
- package/__tests__/api/client.test.ts +0 -330
- package/__tests__/components/CampaignBuilder.test.tsx +0 -103
- package/__tests__/components/CampaignDashboard.test.tsx +0 -89
- package/__tests__/components/CampaignList.test.tsx +0 -144
- package/__tests__/components/MetricsOverview.test.tsx +0 -200
- package/__tests__/components/PerformanceChart.test.tsx +0 -206
- package/__tests__/hooks/useCampaignStore.test.ts +0 -450
- package/__tests__/hooks/useWorkflowValidation.test.ts +0 -176
- package/__tests__/utils/formatting.test.ts +0 -48
- package/__tests__/utils/validation.test.ts +0 -199
- package/__tests__/utils/workflow-helpers.test.ts +0 -134
- package/jest.config.cjs +0 -33
- package/jest.setup.cjs +0 -9
- package/src/api/campaigns.ts +0 -38
- package/src/api/client.ts +0 -131
- package/src/components/CampaignBuilder/index.tsx +0 -123
- package/src/components/CampaignDashboard/MetricsOverview.tsx +0 -41
- package/src/components/CampaignDashboard/PerformanceChart.tsx +0 -49
- package/src/components/CampaignDashboard/index.tsx +0 -52
- package/src/components/CampaignList/index.tsx +0 -53
- package/src/config.ts +0 -39
- package/src/hooks/useCampaignMetrics.ts +0 -41
- package/src/hooks/useCampaignStore.ts +0 -86
- package/src/hooks/useWorkflowValidation.ts +0 -17
- package/src/index.ts +0 -32
- package/src/types/abtest.ts +0 -25
- package/src/types/audience.ts +0 -30
- package/src/types/campaign.ts +0 -44
- package/src/types/index.ts +0 -14
- package/src/types/metrics.ts +0 -36
- package/src/types/schedule.ts +0 -26
- package/src/types/workflow.ts +0 -53
- package/src/utils/formatting.ts +0 -26
- package/src/utils/validation.ts +0 -103
- package/src/utils/workflow-helpers.ts +0 -64
- package/tsconfig.json +0 -24
package/dist/api/client.js
CHANGED
|
@@ -10,6 +10,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
10
10
|
exports.apiClient = exports.APIClient = void 0;
|
|
11
11
|
const config_1 = require("../config");
|
|
12
12
|
class APIClient {
|
|
13
|
+
baseUrl;
|
|
13
14
|
constructor(baseUrl) {
|
|
14
15
|
this.baseUrl = baseUrl || (0, config_1.getConfig)().apiUrl;
|
|
15
16
|
}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type EmailCampaignManagementErrorCode = 'EMAIL_CAMPAIGN_MANAGEMENT_ERROR' | 'INVALID_INPUT' | 'OPERATION_FAILED';
|
|
2
|
+
export interface EmailCampaignManagementErrorOptions {
|
|
3
|
+
cause?: Error;
|
|
4
|
+
code?: EmailCampaignManagementErrorCode;
|
|
5
|
+
context?: Record<string, unknown>;
|
|
6
|
+
}
|
|
7
|
+
export declare class EmailCampaignManagementError extends Error {
|
|
8
|
+
readonly code: EmailCampaignManagementErrorCode;
|
|
9
|
+
readonly context?: Record<string, unknown>;
|
|
10
|
+
constructor(message: string, options?: EmailCampaignManagementErrorOptions);
|
|
11
|
+
}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright (c) 2025 Bernier LLC
|
|
4
|
+
|
|
5
|
+
This file is licensed to the client under a limited-use license.
|
|
6
|
+
The client may use and modify this code *only within the scope of the project it was delivered for*.
|
|
7
|
+
Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.EmailCampaignManagementError = void 0;
|
|
11
|
+
class EmailCampaignManagementError extends Error {
|
|
12
|
+
code;
|
|
13
|
+
context;
|
|
14
|
+
constructor(message, options) {
|
|
15
|
+
super(message, options?.cause ? { cause: options.cause } : undefined);
|
|
16
|
+
this.name = 'EmailCampaignManagementError';
|
|
17
|
+
this.code = options?.code ?? 'EMAIL_CAMPAIGN_MANAGEMENT_ERROR';
|
|
18
|
+
if (options?.context !== undefined) {
|
|
19
|
+
this.context = options.context;
|
|
20
|
+
}
|
|
21
|
+
const maybeCapture = Error.captureStackTrace;
|
|
22
|
+
if (typeof maybeCapture === 'function') {
|
|
23
|
+
maybeCapture(this, this.constructor);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.EmailCampaignManagementError = EmailCampaignManagementError;
|
package/dist/index.d.ts
CHANGED
|
@@ -11,3 +11,4 @@ export * from './utils/formatting';
|
|
|
11
11
|
export * from './utils/workflow-helpers';
|
|
12
12
|
export { getConfig, setConfig, resetConfig } from './config';
|
|
13
13
|
export type { CampaignUIConfig } from './config';
|
|
14
|
+
export { EmailCampaignManagementError, type EmailCampaignManagementErrorCode, type EmailCampaignManagementErrorOptions } from './errors';
|
package/dist/index.js
CHANGED
|
@@ -21,7 +21,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
21
21
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
22
22
|
};
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.resetConfig = exports.setConfig = exports.getConfig = exports.useWorkflowValidation = exports.useEmailMetrics = exports.useCampaignMetrics = exports.useCampaignStore = exports.CampaignList = exports.CampaignBuilder = exports.CampaignDashboard = void 0;
|
|
24
|
+
exports.EmailCampaignManagementError = exports.resetConfig = exports.setConfig = exports.getConfig = exports.useWorkflowValidation = exports.useEmailMetrics = exports.useCampaignMetrics = exports.useCampaignStore = exports.CampaignList = exports.CampaignBuilder = exports.CampaignDashboard = void 0;
|
|
25
25
|
// Components
|
|
26
26
|
var CampaignDashboard_1 = require("./components/CampaignDashboard");
|
|
27
27
|
Object.defineProperty(exports, "CampaignDashboard", { enumerable: true, get: function () { return CampaignDashboard_1.CampaignDashboard; } });
|
|
@@ -50,3 +50,5 @@ var config_1 = require("./config");
|
|
|
50
50
|
Object.defineProperty(exports, "getConfig", { enumerable: true, get: function () { return config_1.getConfig; } });
|
|
51
51
|
Object.defineProperty(exports, "setConfig", { enumerable: true, get: function () { return config_1.setConfig; } });
|
|
52
52
|
Object.defineProperty(exports, "resetConfig", { enumerable: true, get: function () { return config_1.resetConfig; } });
|
|
53
|
+
var errors_1 = require("./errors");
|
|
54
|
+
Object.defineProperty(exports, "EmailCampaignManagementError", { enumerable: true, get: function () { return errors_1.EmailCampaignManagementError; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bernierllc/email-campaign-management",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Marketing email campaign management UI with visual workflow builder, A/B testing, and real-time analytics",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
"date-fns": "^3.0.0",
|
|
23
23
|
"recharts": "^2.10.0",
|
|
24
24
|
"zustand": "^4.4.0",
|
|
25
|
-
"@bernierllc/email-sender": "5.
|
|
26
|
-
"@bernierllc/email-webhook-events": "1.
|
|
27
|
-
"@bernierllc/logger": "1.
|
|
25
|
+
"@bernierllc/email-sender": "5.5.0",
|
|
26
|
+
"@bernierllc/email-webhook-events": "1.7.0",
|
|
27
|
+
"@bernierllc/logger": "1.7.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@testing-library/jest-dom": "^6.0.0",
|
|
@@ -61,6 +61,10 @@
|
|
|
61
61
|
"logger": "integrated"
|
|
62
62
|
}
|
|
63
63
|
},
|
|
64
|
+
"files": [
|
|
65
|
+
"dist/**/*",
|
|
66
|
+
"README.md"
|
|
67
|
+
],
|
|
64
68
|
"scripts": {
|
|
65
69
|
"build": "tsc",
|
|
66
70
|
"dev": "tsc --watch",
|
package/.eslintrc.cjs
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright (c) 2025 Bernier LLC
|
|
3
|
-
|
|
4
|
-
This file is licensed to the client under a limited-use license.
|
|
5
|
-
The client may use and modify this code *only within the scope of the project it was delivered for*.
|
|
6
|
-
Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
module.exports = {
|
|
10
|
-
parser: '@typescript-eslint/parser',
|
|
11
|
-
parserOptions: {
|
|
12
|
-
ecmaVersion: 2020,
|
|
13
|
-
sourceType: 'module',
|
|
14
|
-
ecmaFeatures: {
|
|
15
|
-
jsx: true
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
extends: [
|
|
19
|
-
'eslint:recommended',
|
|
20
|
-
'plugin:@typescript-eslint/recommended',
|
|
21
|
-
'plugin:react/recommended',
|
|
22
|
-
'plugin:react-hooks/recommended'
|
|
23
|
-
],
|
|
24
|
-
plugins: ['@typescript-eslint', 'react', 'react-hooks'],
|
|
25
|
-
env: {
|
|
26
|
-
node: true,
|
|
27
|
-
es6: true,
|
|
28
|
-
browser: true
|
|
29
|
-
},
|
|
30
|
-
settings: {
|
|
31
|
-
react: {
|
|
32
|
-
version: 'detect'
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
rules: {
|
|
36
|
-
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
|
37
|
-
'@typescript-eslint/no-explicit-any': 'warn',
|
|
38
|
-
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
|
|
39
|
-
'react/react-in-jsx-scope': 'off',
|
|
40
|
-
'react/prop-types': 'off',
|
|
41
|
-
'jsx-a11y/control-has-associated-label': 'off',
|
|
42
|
-
'jsx-a11y/click-events-have-key-events': 'off',
|
|
43
|
-
'jsx-a11y/no-noninteractive-element-interactions': 'off'
|
|
44
|
-
}
|
|
45
|
-
};
|
package/CHANGELOG.md
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
# Change Log
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
-
|
|
6
|
-
## [1.3.1](https://github.com/bernierllc/tools/compare/@bernierllc/email-campaign-management@1.3.0...@bernierllc/email-campaign-management@1.3.1) (2026-05-20)
|
|
7
|
-
|
|
8
|
-
**Note:** Version bump only for package @bernierllc/email-campaign-management
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
# 1.3.0 (2026-05-20)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
### Features
|
|
18
|
-
|
|
19
|
-
* **contentful-types:** es2022, errors.ts with error.cause ([b74c636](https://github.com/bernierllc/tools/commit/b74c636e9c4675885c9386dcd413c5163a166ef8))
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
## [1.2.8](https://github.com/bernierllc/tools/compare/@bernierllc/email-campaign-management@1.2.7...@bernierllc/email-campaign-management@1.2.8) (2026-05-19)
|
|
26
|
-
|
|
27
|
-
**Note:** Version bump only for package @bernierllc/email-campaign-management
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
## [1.2.7](https://github.com/bernierllc/tools/compare/@bernierllc/email-campaign-management@1.2.6...@bernierllc/email-campaign-management@1.2.7) (2026-05-19)
|
|
34
|
-
|
|
35
|
-
**Note:** Version bump only for package @bernierllc/email-campaign-management
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
## [1.2.6](https://github.com/bernierllc/tools/compare/@bernierllc/email-campaign-management@1.2.5...@bernierllc/email-campaign-management@1.2.6) (2026-05-19)
|
|
42
|
-
|
|
43
|
-
**Note:** Version bump only for package @bernierllc/email-campaign-management
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
## [1.2.5](https://github.com/bernierllc/tools/compare/@bernierllc/email-campaign-management@1.2.4...@bernierllc/email-campaign-management@1.2.5) (2026-03-30)
|
|
50
|
-
|
|
51
|
-
**Note:** Version bump only for package @bernierllc/email-campaign-management
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
## [1.2.4](https://github.com/bernierllc/tools/compare/@bernierllc/email-campaign-management@1.2.3...@bernierllc/email-campaign-management@1.2.4) (2026-03-21)
|
|
58
|
-
|
|
59
|
-
**Note:** Version bump only for package @bernierllc/email-campaign-management
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
## [1.2.3](https://github.com/bernierllc/tools/compare/@bernierllc/email-campaign-management@1.2.2...@bernierllc/email-campaign-management@1.2.3) (2026-03-18)
|
|
66
|
-
|
|
67
|
-
**Note:** Version bump only for package @bernierllc/email-campaign-management
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
## [1.2.2](https://github.com/bernierllc/tools/compare/@bernierllc/email-campaign-management@1.2.1...@bernierllc/email-campaign-management@1.2.2) (2026-03-09)
|
|
74
|
-
|
|
75
|
-
**Note:** Version bump only for package @bernierllc/email-campaign-management
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
## [1.2.1](https://github.com/bernierllc/tools/compare/@bernierllc/email-campaign-management@1.2.0...@bernierllc/email-campaign-management@1.2.1) (2026-03-03)
|
|
82
|
-
|
|
83
|
-
**Note:** Version bump only for package @bernierllc/email-campaign-management
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
# 1.2.0 (2025-12-25)
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
### Bug Fixes
|
|
93
|
-
|
|
94
|
-
* **ci:** add lerna version step before publish ([3d20300](https://github.com/bernierllc/tools/commit/3d203002143bf353fffafe4f8a78a99009567347))
|
|
95
|
-
* **ci:** fix release workflow + convert internal deps to workspace:* ([01c078b](https://github.com/bernierllc/tools/commit/01c078b49d6025f7eef750f79207a1c71c8d85dc))
|
|
96
|
-
* update neverhub-adapter deps to workspace:* and publish 0.1.2 ([f0e3d04](https://github.com/bernierllc/tools/commit/f0e3d04d8d4f094e3bb899ddf81e93243d16e2c2))
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
### Features
|
|
100
|
-
|
|
101
|
-
* complete @bernierllc/email-campaign-management implementation ([4fa7630](https://github.com/bernierllc/tools/commit/4fa76307e829bb4511f775b0373ecbd7705556c7))
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
# 1.1.0 (2025-12-25)
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
### Bug Fixes
|
|
111
|
-
|
|
112
|
-
* **ci:** fix release workflow + convert internal deps to workspace:* ([01c078b](https://github.com/bernierllc/tools/commit/01c078b49d6025f7eef750f79207a1c71c8d85dc))
|
|
113
|
-
* update neverhub-adapter deps to workspace:* and publish 0.1.2 ([f0e3d04](https://github.com/bernierllc/tools/commit/f0e3d04d8d4f094e3bb899ddf81e93243d16e2c2))
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
### Features
|
|
117
|
-
|
|
118
|
-
* complete @bernierllc/email-campaign-management implementation ([4fa7630](https://github.com/bernierllc/tools/commit/4fa76307e829bb4511f775b0373ecbd7705556c7))
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
# @bernierllc/email-campaign-management
|
|
125
|
-
|
|
126
|
-
## 1.0.7
|
|
127
|
-
|
|
128
|
-
### Patch Changes
|
|
129
|
-
|
|
130
|
-
- Updated dependencies [[`c45c75c`](https://github.com/bernierllc/tools/commit/c45c75ce2db9cc9f45fe1be6c73e8018a427727c)]:
|
|
131
|
-
- @bernierllc/email-webhook-events@1.0.1
|
|
132
|
-
|
|
133
|
-
## 1.0.6
|
|
134
|
-
|
|
135
|
-
### Patch Changes
|
|
136
|
-
|
|
137
|
-
- Updated dependencies [[`73c1d1e`](https://github.com/bernierllc/tools/commit/73c1d1e46114cf2ccfd5b74b83743361247f4502), [`73c1d1e`](https://github.com/bernierllc/tools/commit/73c1d1e46114cf2ccfd5b74b83743361247f4502)]:
|
|
138
|
-
- @bernierllc/email-sender@3.1.0
|
|
139
|
-
- @bernierllc/logger@1.1.0
|
|
140
|
-
|
|
141
|
-
## 1.0.5
|
|
142
|
-
|
|
143
|
-
### Patch Changes
|
|
144
|
-
|
|
145
|
-
- Updated dependencies [[`24899fa`](https://github.com/bernierllc/tools/commit/24899fa4eaf80ae329f7bd74483cf97a132f5d4c)]:
|
|
146
|
-
- @bernierllc/logger@1.0.4
|
|
147
|
-
|
|
148
|
-
## 1.0.4
|
|
149
|
-
|
|
150
|
-
### Patch Changes
|
|
151
|
-
|
|
152
|
-
- Updated dependencies [[`a314763`](https://github.com/bernierllc/tools/commit/a31476336717301e410da2b0b64c8f1ee44c0e8d)]:
|
|
153
|
-
- @bernierllc/email-sender@3.0.5
|
|
154
|
-
|
|
155
|
-
## 1.0.3
|
|
156
|
-
|
|
157
|
-
### Patch Changes
|
|
158
|
-
|
|
159
|
-
- Updated dependencies [[`a65f28c`](https://github.com/bernierllc/tools/commit/a65f28c2a1d09da8e8c7c23dcebd8f6606d9783f)]:
|
|
160
|
-
- @bernierllc/email-sender@3.0.4
|
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright (c) 2025 Bernier LLC
|
|
3
|
-
|
|
4
|
-
This file is licensed to the client under a limited-use license.
|
|
5
|
-
The client may use and modify this code *only within the scope of the project it was delivered for*.
|
|
6
|
-
Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
getCampaigns,
|
|
11
|
-
getCampaign,
|
|
12
|
-
createCampaign,
|
|
13
|
-
updateCampaign,
|
|
14
|
-
deleteCampaign,
|
|
15
|
-
getCampaignMetrics,
|
|
16
|
-
getEmailMetrics
|
|
17
|
-
} from '../../src/api/campaigns';
|
|
18
|
-
import { apiClient } from '../../src/api/client';
|
|
19
|
-
import { CampaignType } from '../../src/types';
|
|
20
|
-
|
|
21
|
-
jest.mock('../../src/api/client', () => ({
|
|
22
|
-
apiClient: {
|
|
23
|
-
get: jest.fn(),
|
|
24
|
-
post: jest.fn(),
|
|
25
|
-
put: jest.fn(),
|
|
26
|
-
delete: jest.fn()
|
|
27
|
-
}
|
|
28
|
-
}));
|
|
29
|
-
|
|
30
|
-
const mockApiClient = apiClient as jest.Mocked<typeof apiClient>;
|
|
31
|
-
|
|
32
|
-
describe('campaigns API', () => {
|
|
33
|
-
beforeEach(() => {
|
|
34
|
-
jest.clearAllMocks();
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
describe('getCampaigns', () => {
|
|
38
|
-
it('should call apiClient.get with correct endpoint', async () => {
|
|
39
|
-
const mockResponse = { success: true, data: [] };
|
|
40
|
-
mockApiClient.get.mockResolvedValueOnce(mockResponse);
|
|
41
|
-
|
|
42
|
-
const result = await getCampaigns();
|
|
43
|
-
|
|
44
|
-
expect(mockApiClient.get).toHaveBeenCalledWith('/campaigns');
|
|
45
|
-
expect(result).toEqual(mockResponse);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('should return error response on failure', async () => {
|
|
49
|
-
const mockError = { success: false, error: 'Failed to fetch' };
|
|
50
|
-
mockApiClient.get.mockResolvedValueOnce(mockError);
|
|
51
|
-
|
|
52
|
-
const result = await getCampaigns();
|
|
53
|
-
|
|
54
|
-
expect(result).toEqual(mockError);
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
describe('getCampaign', () => {
|
|
59
|
-
it('should call apiClient.get with campaign ID', async () => {
|
|
60
|
-
const mockResponse = { success: true, data: { id: 'campaign-123' } };
|
|
61
|
-
mockApiClient.get.mockResolvedValueOnce(mockResponse);
|
|
62
|
-
|
|
63
|
-
const result = await getCampaign('campaign-123');
|
|
64
|
-
|
|
65
|
-
expect(mockApiClient.get).toHaveBeenCalledWith('/campaigns/campaign-123');
|
|
66
|
-
expect(result).toEqual(mockResponse);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('should handle non-existent campaign', async () => {
|
|
70
|
-
const mockError = { success: false, error: 'Campaign not found' };
|
|
71
|
-
mockApiClient.get.mockResolvedValueOnce(mockError);
|
|
72
|
-
|
|
73
|
-
const result = await getCampaign('nonexistent');
|
|
74
|
-
|
|
75
|
-
expect(result).toEqual(mockError);
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
describe('createCampaign', () => {
|
|
80
|
-
it('should call apiClient.post with campaign data', async () => {
|
|
81
|
-
const campaignData = { name: 'New Campaign', type: 'one-time' as CampaignType };
|
|
82
|
-
const mockResponse = { success: true, data: { id: 'new-id', ...campaignData } };
|
|
83
|
-
mockApiClient.post.mockResolvedValueOnce(mockResponse);
|
|
84
|
-
|
|
85
|
-
const result = await createCampaign(campaignData);
|
|
86
|
-
|
|
87
|
-
expect(mockApiClient.post).toHaveBeenCalledWith('/campaigns', campaignData);
|
|
88
|
-
expect(result).toEqual(mockResponse);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('should handle validation errors', async () => {
|
|
92
|
-
const mockError = { success: false, error: 'Name is required' };
|
|
93
|
-
mockApiClient.post.mockResolvedValueOnce(mockError);
|
|
94
|
-
|
|
95
|
-
const result = await createCampaign({});
|
|
96
|
-
|
|
97
|
-
expect(result).toEqual(mockError);
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
describe('updateCampaign', () => {
|
|
102
|
-
it('should call apiClient.put with campaign ID and updates', async () => {
|
|
103
|
-
const updates = { name: 'Updated Name' };
|
|
104
|
-
const mockResponse = { success: true, data: { id: 'campaign-123', name: 'Updated Name' } };
|
|
105
|
-
mockApiClient.put.mockResolvedValueOnce(mockResponse);
|
|
106
|
-
|
|
107
|
-
const result = await updateCampaign('campaign-123', updates);
|
|
108
|
-
|
|
109
|
-
expect(mockApiClient.put).toHaveBeenCalledWith('/campaigns/campaign-123', updates);
|
|
110
|
-
expect(result).toEqual(mockResponse);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it('should handle update failures', async () => {
|
|
114
|
-
const mockError = { success: false, error: 'Update failed' };
|
|
115
|
-
mockApiClient.put.mockResolvedValueOnce(mockError);
|
|
116
|
-
|
|
117
|
-
const result = await updateCampaign('campaign-123', { name: '' });
|
|
118
|
-
|
|
119
|
-
expect(result).toEqual(mockError);
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
describe('deleteCampaign', () => {
|
|
124
|
-
it('should call apiClient.delete with campaign ID', async () => {
|
|
125
|
-
const mockResponse = { success: true };
|
|
126
|
-
mockApiClient.delete.mockResolvedValueOnce(mockResponse);
|
|
127
|
-
|
|
128
|
-
const result = await deleteCampaign('campaign-123');
|
|
129
|
-
|
|
130
|
-
expect(mockApiClient.delete).toHaveBeenCalledWith('/campaigns/campaign-123');
|
|
131
|
-
expect(result).toEqual(mockResponse);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it('should handle delete failures', async () => {
|
|
135
|
-
const mockError = { success: false, error: 'Cannot delete active campaign' };
|
|
136
|
-
mockApiClient.delete.mockResolvedValueOnce(mockError);
|
|
137
|
-
|
|
138
|
-
const result = await deleteCampaign('active-campaign');
|
|
139
|
-
|
|
140
|
-
expect(result).toEqual(mockError);
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
describe('getCampaignMetrics', () => {
|
|
145
|
-
it('should call apiClient.get with metrics endpoint', async () => {
|
|
146
|
-
const mockMetrics = {
|
|
147
|
-
success: true,
|
|
148
|
-
data: {
|
|
149
|
-
campaignId: 'campaign-123',
|
|
150
|
-
sent: 1000,
|
|
151
|
-
delivered: 950,
|
|
152
|
-
bounced: 50,
|
|
153
|
-
opened: 400,
|
|
154
|
-
clicked: 100,
|
|
155
|
-
converted: 20,
|
|
156
|
-
unsubscribed: 5,
|
|
157
|
-
openRate: 40,
|
|
158
|
-
clickRate: 10,
|
|
159
|
-
conversionRate: 2,
|
|
160
|
-
lastUpdated: new Date()
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
mockApiClient.get.mockResolvedValueOnce(mockMetrics);
|
|
164
|
-
|
|
165
|
-
const result = await getCampaignMetrics('campaign-123');
|
|
166
|
-
|
|
167
|
-
expect(mockApiClient.get).toHaveBeenCalledWith('/campaigns/campaign-123/metrics');
|
|
168
|
-
expect(result).toEqual(mockMetrics);
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
it('should handle metrics not available', async () => {
|
|
172
|
-
const mockError = { success: false, error: 'Metrics not available yet' };
|
|
173
|
-
mockApiClient.get.mockResolvedValueOnce(mockError);
|
|
174
|
-
|
|
175
|
-
const result = await getCampaignMetrics('new-campaign');
|
|
176
|
-
|
|
177
|
-
expect(result).toEqual(mockError);
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
describe('getEmailMetrics', () => {
|
|
182
|
-
it('should call apiClient.get with email metrics endpoint', async () => {
|
|
183
|
-
const mockMetrics = {
|
|
184
|
-
success: true,
|
|
185
|
-
data: [
|
|
186
|
-
{ emailId: 'email-1', opened: true, clicked: false },
|
|
187
|
-
{ emailId: 'email-2', opened: true, clicked: true }
|
|
188
|
-
]
|
|
189
|
-
};
|
|
190
|
-
mockApiClient.get.mockResolvedValueOnce(mockMetrics);
|
|
191
|
-
|
|
192
|
-
const result = await getEmailMetrics('campaign-123');
|
|
193
|
-
|
|
194
|
-
expect(mockApiClient.get).toHaveBeenCalledWith('/campaigns/campaign-123/emails/metrics');
|
|
195
|
-
expect(result).toEqual(mockMetrics);
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
it('should handle no emails sent yet', async () => {
|
|
199
|
-
const mockResponse = { success: true, data: [] };
|
|
200
|
-
mockApiClient.get.mockResolvedValueOnce(mockResponse);
|
|
201
|
-
|
|
202
|
-
const result = await getEmailMetrics('draft-campaign');
|
|
203
|
-
|
|
204
|
-
expect(result.success).toBe(true);
|
|
205
|
-
expect(result.data).toEqual([]);
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
it('should handle fetch failure', async () => {
|
|
209
|
-
const mockError = { success: false, error: 'Service unavailable' };
|
|
210
|
-
mockApiClient.get.mockResolvedValueOnce(mockError);
|
|
211
|
-
|
|
212
|
-
const result = await getEmailMetrics('campaign-123');
|
|
213
|
-
|
|
214
|
-
expect(result).toEqual(mockError);
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
});
|