1
- import path from 'node:path' ;
2
1
import {
3
2
containsEmailTemplate ,
4
3
removeFilenameExtension ,
5
4
} from './contains-email-template' ;
5
+ import type { EmailsDirectory } from './get-emails-directory-metadata' ;
6
6
7
- describe ( 'removeFilenameExtension()' , async ( ) => {
7
+ describe ( 'removeFilenameExtension()' , ( ) => {
8
8
it ( 'should work with a single .' , ( ) => {
9
9
expect ( removeFilenameExtension ( 'email-template.tsx' ) ) . toBe (
10
10
'email-template' ,
@@ -22,19 +22,15 @@ describe('removeFilenameExtension()', async () => {
22
22
} ) ;
23
23
} ) ;
24
24
25
- test ( 'containsEmailTemplate()' , async ( ) => {
26
- const emailsDirectoryPath = path . resolve (
27
- __dirname ,
28
- '../../../../apps/demo/emails' ,
29
- ) ;
30
- const directory = {
31
- absolutePath : emailsDirectoryPath ,
25
+ describe ( 'containsEmailTemplate()' , ( ) => {
26
+ const directory : EmailsDirectory = {
27
+ absolutePath : '/fake/path/emails' ,
32
28
directoryName : 'emails' ,
33
29
relativePath : '' ,
34
30
emailFilenames : [ ] ,
35
31
subDirectories : [
36
32
{
37
- absolutePath : ` ${ emailsDirectoryPath } / magic-links` ,
33
+ absolutePath : '/fake/path/emails/ magic-links' ,
38
34
directoryName : 'magic-links' ,
39
35
relativePath : 'magic-links' ,
40
36
emailFilenames : [
@@ -45,10 +41,18 @@ test('containsEmailTemplate()', async () => {
45
41
'raycast-magic-link' ,
46
42
'slack-confirm' ,
47
43
] ,
48
- subDirectories : [ ] ,
44
+ subDirectories : [
45
+ {
46
+ absolutePath : '/fake/path/emails/magic-links/resend' ,
47
+ directoryName : 'resend' ,
48
+ emailFilenames : [ 'verify-email' ] ,
49
+ relativePath : 'magic-links/resend' ,
50
+ subDirectories : [ ] ,
51
+ } ,
52
+ ] ,
49
53
} ,
50
54
{
51
- absolutePath : ` ${ emailsDirectoryPath } / newsletters` ,
55
+ absolutePath : '/fake/path/emails/ newsletters' ,
52
56
directoryName : 'newsletters' ,
53
57
relativePath : 'newsletters' ,
54
58
emailFilenames : [
@@ -59,7 +63,7 @@ test('containsEmailTemplate()', async () => {
59
63
subDirectories : [ ] ,
60
64
} ,
61
65
{
62
- absolutePath : ` ${ emailsDirectoryPath } / notifications` ,
66
+ absolutePath : '/fake/path/emails/ notifications' ,
63
67
directoryName : 'notifications' ,
64
68
relativePath : 'notifications' ,
65
69
emailFilenames : [
@@ -71,37 +75,50 @@ test('containsEmailTemplate()', async () => {
71
75
subDirectories : [ ] ,
72
76
} ,
73
77
{
74
- absolutePath : ` ${ emailsDirectoryPath } / receipts` ,
78
+ absolutePath : '/fake/path/emails/ receipts' ,
75
79
directoryName : 'receipts' ,
76
80
relativePath : 'receipts' ,
77
81
emailFilenames : [ 'apple-receipt' , 'nike-receipt' ] ,
78
82
subDirectories : [ ] ,
79
83
} ,
80
84
{
81
- absolutePath : ` ${ emailsDirectoryPath } / reset-password` ,
85
+ absolutePath : '/fake/path/emails/ reset-password' ,
82
86
directoryName : 'reset-password' ,
83
87
relativePath : 'reset-password' ,
84
88
emailFilenames : [ 'dropbox-reset-password' , 'twitch-reset-password' ] ,
85
89
subDirectories : [ ] ,
86
90
} ,
87
91
{
88
- absolutePath : ` ${ emailsDirectoryPath } / reviews` ,
92
+ absolutePath : '/fake/path/emails/ reviews' ,
89
93
directoryName : 'reviews' ,
90
94
relativePath : 'reviews' ,
91
95
emailFilenames : [ 'airbnb-review' , 'amazon-review' ] ,
92
96
subDirectories : [ ] ,
93
97
} ,
94
98
{
95
- absolutePath : ` ${ emailsDirectoryPath } / welcome` ,
99
+ absolutePath : '/fake/path/emails/ welcome' ,
96
100
directoryName : 'welcome' ,
97
101
relativePath : 'welcome' ,
98
102
emailFilenames : [ 'koala-welcome' , 'netlify-welcome' , 'stripe-welcome' ] ,
99
103
subDirectories : [ ] ,
100
104
} ,
101
105
] ,
102
106
} ;
103
- expect ( containsEmailTemplate ( 'welcome/koala-welcome' , directory ) ) . toBe ( true ) ;
104
- expect ( containsEmailTemplate ( 'welcome/missing-template' , directory ) ) . toBe (
105
- false ,
106
- ) ;
107
+ it ( 'should work with email inside a single sub directory' , ( ) => {
108
+ expect ( containsEmailTemplate ( 'welcome/koala-welcome' , directory ) ) . toBe (
109
+ true ,
110
+ ) ;
111
+ expect ( containsEmailTemplate ( 'welcome/missing-template' , directory ) ) . toBe (
112
+ false ,
113
+ ) ;
114
+ } ) ;
115
+
116
+ it ( 'should work with email inside a second sub directory' , ( ) => {
117
+ expect (
118
+ containsEmailTemplate ( 'magic-links/resend/verify-email' , directory ) ,
119
+ ) . toBe ( true ) ;
120
+ expect (
121
+ containsEmailTemplate ( 'magic-links/resend/missing-template' , directory ) ,
122
+ ) . toBe ( false ) ;
123
+ } ) ;
107
124
} ) ;
0 commit comments