Skip to content

Commit aa0e622

Browse files
joaopcmlucasfcostarenovate[bot]vcapretzgabrielmfern
committed
chore: limited variable types (#692)
Co-authored-by: Lucas da Costa <[email protected]> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Vitor Capretz <[email protected]> Co-authored-by: Gabriel Miranda <[email protected]> Co-authored-by: Ty Mick <[email protected]> Co-authored-by: Isabella Aquino <[email protected]> Co-authored-by: Alexandre Cisneiros <[email protected]> Co-authored-by: Carolina de Moraes Josephik <[email protected]> Co-authored-by: Carolina de Moraes Josephik <[email protected]> Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> Co-authored-by: Vitor Capretz <[email protected]> Co-authored-by: Cassio Zen <[email protected]> Co-authored-by: Bu Kinoshita <[email protected]> Co-authored-by: Zeno Rocha <[email protected]>
1 parent da8ed3d commit aa0e622

File tree

4 files changed

+24
-169
lines changed

4 files changed

+24
-169
lines changed

src/templates/interfaces/create-template-options.interface.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import type { PostOptions } from '../../common/interfaces';
22
import type { RequireAtLeastOne } from '../../common/interfaces/require-at-least-one';
33
import type { ErrorResponse } from '../../interfaces';
4-
import type {
5-
Template,
6-
TemplateVariable,
7-
TemplateVariableListFallbackType,
8-
} from './template';
4+
import type { Template, TemplateVariable } from './template';
95

106
type TemplateContentCreationOptions = RequireAtLeastOne<{
117
html: string;
@@ -22,18 +18,6 @@ type TemplateVariableCreationOptions = Pick<TemplateVariable, 'key' | 'type'> &
2218
type: 'number';
2319
fallbackValue?: number | null;
2420
}
25-
| {
26-
type: 'boolean';
27-
fallbackValue?: boolean | null;
28-
}
29-
| {
30-
type: 'object';
31-
fallbackValue: Record<string, unknown>;
32-
}
33-
| {
34-
type: 'list';
35-
fallbackValue: TemplateVariableListFallbackType;
36-
}
3721
);
3822

3923
type TemplateOptionalFieldsForCreation = Partial<

src/templates/interfaces/template.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,10 @@ export interface Template {
1616
current_version_id: string;
1717
}
1818

19-
export type TemplateVariableListFallbackType =
20-
| string[]
21-
| number[]
22-
| boolean[]
23-
| Record<string, unknown>[];
24-
2519
export interface TemplateVariable {
2620
key: string;
27-
fallback_value:
28-
| string
29-
| number
30-
| boolean
31-
| Record<string, unknown>
32-
| TemplateVariableListFallbackType
33-
| null;
34-
type: 'string' | 'number' | 'boolean' | 'object' | 'list';
21+
fallback_value: string | number | null;
22+
type: 'string' | 'number';
3523
created_at: string;
3624
updated_at: string;
3725
}

src/templates/interfaces/update-template.interface.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import type { ErrorResponse } from '../../interfaces';
2-
import type {
3-
Template,
4-
TemplateVariable,
5-
TemplateVariableListFallbackType,
6-
} from './template';
2+
import type { Template, TemplateVariable } from './template';
73

84
type TemplateVariableUpdateOptions = Pick<TemplateVariable, 'key' | 'type'> &
95
(
@@ -15,18 +11,6 @@ type TemplateVariableUpdateOptions = Pick<TemplateVariable, 'key' | 'type'> &
1511
type: 'number';
1612
fallbackValue?: number | null;
1713
}
18-
| {
19-
type: 'boolean';
20-
fallbackValue?: boolean | null;
21-
}
22-
| {
23-
type: 'object';
24-
fallbackValue: Record<string, unknown>;
25-
}
26-
| {
27-
type: 'list';
28-
fallbackValue: TemplateVariableListFallbackType;
29-
}
3014
);
3115

3216
export interface UpdateTemplateOptions

src/templates/templates.spec.ts

Lines changed: 20 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -264,61 +264,6 @@ describe('Templates', () => {
264264
'Failed to render React component. Make sure to install `@react-email/render`',
265265
);
266266
});
267-
268-
it('creates a template with object and list variable types', async () => {
269-
const payload: CreateTemplateOptions = {
270-
name: 'Complex Variables Template',
271-
html: '<h1>Welcome {{{userProfile.name}}}!</h1><p>Your tags: {{{tags}}}</p>',
272-
variables: [
273-
{
274-
key: 'userProfile',
275-
type: 'object',
276-
fallbackValue: { name: 'John', age: 30 },
277-
},
278-
{
279-
key: 'tags',
280-
type: 'list',
281-
fallbackValue: ['premium', 'vip'],
282-
},
283-
{
284-
key: 'scores',
285-
type: 'list',
286-
fallbackValue: [95, 87, 92],
287-
},
288-
{
289-
key: 'flags',
290-
type: 'list',
291-
fallbackValue: [true, false, true],
292-
},
293-
{
294-
key: 'items',
295-
type: 'list',
296-
fallbackValue: [{ id: 1 }, { id: 2 }],
297-
},
298-
],
299-
};
300-
const response: CreateTemplateResponseSuccess = {
301-
object: 'template',
302-
id: 'fd61172c-cafc-40f5-b049-b45947779a29',
303-
};
304-
305-
mockSuccessResponse(response, {
306-
headers: { Authorization: `Bearer ${TEST_API_KEY}` },
307-
});
308-
309-
const resend = new Resend(TEST_API_KEY);
310-
await expect(
311-
resend.templates.create(payload),
312-
).resolves.toMatchInlineSnapshot(`
313-
{
314-
"data": {
315-
"id": "fd61172c-cafc-40f5-b049-b45947779a29",
316-
"object": "template",
317-
},
318-
"error": null,
319-
}
320-
`);
321-
});
322267
});
323268

324269
describe('remove', () => {
@@ -541,65 +486,6 @@ describe('Templates', () => {
541486
}
542487
`);
543488
});
544-
545-
it('updates a template with object and list variable types', async () => {
546-
const id = 'fd61172c-cafc-40f5-b049-b45947779a29';
547-
const payload: UpdateTemplateOptions = {
548-
name: 'Updated Complex Variables Template',
549-
html: '<h1>Updated Welcome {{{config.theme}}}!</h1><p>Permissions: {{{permissions}}}</p>',
550-
variables: [
551-
{
552-
key: 'config',
553-
type: 'object',
554-
fallbackValue: { theme: 'dark', lang: 'en' },
555-
},
556-
{
557-
key: 'permissions',
558-
type: 'list',
559-
fallbackValue: ['read', 'write'],
560-
},
561-
{
562-
key: 'counts',
563-
type: 'list',
564-
fallbackValue: [10, 20, 30],
565-
},
566-
{
567-
key: 'enabled',
568-
type: 'list',
569-
fallbackValue: [true, false],
570-
},
571-
{
572-
key: 'metadata',
573-
type: 'list',
574-
fallbackValue: [{ key: 'a' }, { key: 'b' }],
575-
},
576-
],
577-
};
578-
const response = {
579-
object: 'template',
580-
id,
581-
};
582-
583-
mockSuccessResponse(response, {
584-
headers: {
585-
Authorization: 'Bearer re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop',
586-
},
587-
});
588-
589-
const resend = new Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
590-
591-
await expect(
592-
resend.templates.update(id, payload),
593-
).resolves.toMatchInlineSnapshot(`
594-
{
595-
"data": {
596-
"id": "fd61172c-cafc-40f5-b049-b45947779a29",
597-
"object": "template",
598-
},
599-
"error": null,
600-
}
601-
`);
602-
});
603489
});
604490

605491
describe('get', () => {
@@ -1015,20 +901,33 @@ describe('Templates', () => {
1015901

1016902
const resend = new Resend(TEST_API_KEY);
1017903

904+
// Test before and limit together
1018905
await resend.templates.list({
1019906
before: 'cursor1',
907+
limit: 25,
908+
});
909+
910+
// Verify before and limit pagination parameters are included
911+
const [firstUrl] = fetchMock.mock.calls[0];
912+
const firstParsedUrl = new URL(firstUrl as string);
913+
914+
expect(firstParsedUrl.pathname).toBe('/templates');
915+
expect(firstParsedUrl.searchParams.get('before')).toBe('cursor1');
916+
expect(firstParsedUrl.searchParams.get('limit')).toBe('25');
917+
918+
// Test after and limit together
919+
await resend.templates.list({
1020920
after: 'cursor2',
1021921
limit: 25,
1022922
});
1023923

1024-
// Verify all pagination parameters are included
1025-
const [url] = fetchMock.mock.calls[0];
1026-
const parsedUrl = new URL(url as string);
924+
// Verify after and limit pagination parameters are included
925+
const [secondUrl] = fetchMock.mock.calls[1];
926+
const secondParsedUrl = new URL(secondUrl as string);
1027927

1028-
expect(parsedUrl.pathname).toBe('/templates');
1029-
expect(parsedUrl.searchParams.get('before')).toBe('cursor1');
1030-
expect(parsedUrl.searchParams.get('after')).toBe('cursor2');
1031-
expect(parsedUrl.searchParams.get('limit')).toBe('25');
928+
expect(secondParsedUrl.pathname).toBe('/templates');
929+
expect(secondParsedUrl.searchParams.get('after')).toBe('cursor2');
930+
expect(secondParsedUrl.searchParams.get('limit')).toBe('25');
1032931
});
1033932
});
1034933
});

0 commit comments

Comments
 (0)