Skip to content

Commit 9328788

Browse files
committed
fix remainiing test issues
1 parent e3437d4 commit 9328788

File tree

11 files changed

+56
-34
lines changed

11 files changed

+56
-34
lines changed

src/contact-properties/contact-properties.spec.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('ContactProperties', () => {
3737
};
3838

3939
mockSuccessResponse(response, {
40-
headers: { Authorization: 'Bearer re_924b3rjh2387fbewf823' },
40+
headers: { Authorization: 'Bearer re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop' },
4141
});
4242
const resend = new Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
4343
await expect(
@@ -50,7 +50,7 @@ describe('ContactProperties', () => {
5050
},
5151
"error": null,
5252
"headers": {
53-
"authorization": "Bearer re_924b3rjh2387fbewf823",
53+
"authorization": "Bearer re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop",
5454
"content-type": "application/json",
5555
},
5656
}
@@ -117,7 +117,7 @@ describe('ContactProperties', () => {
117117
has_more: false,
118118
};
119119
mockSuccessResponse(response, {
120-
headers: { Authorization: 'Bearer re_924b3rjh2387fbewf823' },
120+
headers: { Authorization: 'Bearer re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop' },
121121
});
122122
const resend = new Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
123123
await expect(
@@ -147,6 +147,10 @@ describe('ContactProperties', () => {
147147
"object": "list",
148148
},
149149
"error": null,
150+
"headers": {
151+
"authorization": "Bearer re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop",
152+
"content-type": "application/json",
153+
},
150154
}
151155
`);
152156
});
@@ -163,7 +167,7 @@ describe('ContactProperties', () => {
163167
created_at: '2021-01-01T00:00:00.000Z',
164168
};
165169
mockSuccessResponse(response, {
166-
headers: { Authorization: 'Bearer re_924b3rjh2387fbewf823' },
170+
headers: { Authorization: 'Bearer re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop' },
167171
});
168172
const resend = new Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
169173
await expect(
@@ -179,6 +183,10 @@ describe('ContactProperties', () => {
179183
"type": "string",
180184
},
181185
"error": null,
186+
"headers": {
187+
"authorization": "Bearer re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop",
188+
"content-type": "application/json",
189+
},
182190
}
183191
`);
184192
});
@@ -203,6 +211,7 @@ describe('ContactProperties', () => {
203211
"name": "missing_required_field",
204212
"statusCode": null,
205213
},
214+
"headers": null,
206215
}
207216
`);
208217
});
@@ -247,7 +256,7 @@ describe('ContactProperties', () => {
247256
object: 'contact_property',
248257
};
249258
mockSuccessResponse(response, {
250-
headers: { Authorization: 'Bearer re_924b3rjh2387fbewf823' },
259+
headers: { Authorization: 'Bearer re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop' },
251260
});
252261
const resend = new Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
253262
await expect(
@@ -260,7 +269,7 @@ describe('ContactProperties', () => {
260269
},
261270
"error": null,
262271
"headers": {
263-
"authorization": "Bearer re_924b3rjh2387fbewf823",
272+
"authorization": "Bearer re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop",
264273
"content-type": "application/json",
265274
},
266275
}
@@ -290,6 +299,7 @@ describe('ContactProperties', () => {
290299
"name": "missing_required_field",
291300
"statusCode": null,
292301
},
302+
"headers": null,
293303
}
294304
`);
295305
});
@@ -303,7 +313,7 @@ describe('ContactProperties', () => {
303313
object: 'contact_property',
304314
};
305315
mockSuccessResponse(response, {
306-
headers: { Authorization: 'Bearer re_924b3rjh2387fbewf823' },
316+
headers: { Authorization: 'Bearer re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop' },
307317
});
308318
const resend = new Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
309319
await expect(
@@ -317,7 +327,7 @@ describe('ContactProperties', () => {
317327
},
318328
"error": null,
319329
"headers": {
320-
"authorization": "Bearer re_924b3rjh2387fbewf823",
330+
"authorization": "Bearer re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop",
321331
"content-type": "application/json",
322332
},
323333
}
@@ -344,6 +354,7 @@ describe('ContactProperties', () => {
344354
"name": "missing_required_field",
345355
"statusCode": null,
346356
},
357+
"headers": null,
347358
}
348359
`);
349360
});

src/contact-properties/contact-properties.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import type {
2929
} from './interfaces/update-contact-property-options.interface';
3030

3131
export class ContactProperties {
32-
constructor(private readonly resend: Resend) {}
32+
constructor(private readonly resend: Resend) { }
3333

3434
async create(
3535
options: CreateContactPropertyOptions,
@@ -61,6 +61,7 @@ export class ContactProperties {
6161
parseContactPropertyFromApi(apiContactProperty),
6262
),
6363
},
64+
headers: response.headers,
6465
error: null,
6566
};
6667
}
@@ -72,6 +73,7 @@ export class ContactProperties {
7273
if (!id) {
7374
return {
7475
data: null,
76+
headers: null,
7577
error: {
7678
message: 'Missing `id` field.',
7779
statusCode: null,
@@ -86,6 +88,7 @@ export class ContactProperties {
8688
if (response.data) {
8789
return {
8890
data: parseContactPropertyFromApi(response.data),
91+
headers: response.headers,
8992
error: null,
9093
};
9194
}
@@ -99,6 +102,7 @@ export class ContactProperties {
99102
if (!payload.id) {
100103
return {
101104
data: null,
105+
headers: null,
102106
error: {
103107
message: 'Missing `id` field.',
104108
statusCode: null,
@@ -119,6 +123,7 @@ export class ContactProperties {
119123
if (!id) {
120124
return {
121125
data: null,
126+
headers: null,
122127
error: {
123128
message: 'Missing `id` field.',
124129
statusCode: null,

src/contacts/contacts.ts

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,13 @@ export class Contacts {
9191

9292
async get(options: GetContactOptions): Promise<GetContactResponse> {
9393
if (typeof options === 'string') {
94-
const data = await this.resend.get<GetContactResponseSuccess>(
95-
`/contacts/${options}`,
96-
);
97-
return data;
94+
return this.resend.get<GetContactResponseSuccess>(`/contacts/${options}`);
9895
}
9996

10097
if (!options.id && !options.email) {
10198
return {
10299
data: null,
100+
headers: null,
103101
error: {
104102
message: 'Missing `id` or `email` field.',
105103
statusCode: null,
@@ -109,22 +107,21 @@ export class Contacts {
109107
}
110108

111109
if (!options.audienceId) {
112-
const data = await this.resend.get<GetContactResponseSuccess>(
110+
return this.resend.get<GetContactResponseSuccess>(
113111
`/contacts/${options?.email ? options?.email : options?.id}`,
114112
);
115-
return data;
116113
}
117114

118-
const data = await this.resend.get<GetContactResponseSuccess>(
115+
return this.resend.get<GetContactResponseSuccess>(
119116
`/audiences/${options.audienceId}/contacts/${options?.email ? options?.email : options?.id}`,
120117
);
121-
return data;
122118
}
123119

124120
async update(options: UpdateContactOptions): Promise<UpdateContactResponse> {
125121
if (!options.id && !options.email) {
126122
return {
127123
data: null,
124+
headers: null,
128125
error: {
129126
message: 'Missing `id` or `email` field.',
130127
statusCode: null,
@@ -158,15 +155,15 @@ export class Contacts {
158155

159156
async remove(payload: RemoveContactOptions): Promise<RemoveContactsResponse> {
160157
if (typeof payload === 'string') {
161-
const data = await this.resend.delete<RemoveContactsResponseSuccess>(
158+
return this.resend.delete<RemoveContactsResponseSuccess>(
162159
`/contacts/${payload}`,
163160
);
164-
return data;
165161
}
166162

167163
if (!payload.id && !payload.email) {
168164
return {
169165
data: null,
166+
headers: null,
170167
error: {
171168
message: 'Missing `id` or `email` field.',
172169
statusCode: null,
@@ -176,18 +173,14 @@ export class Contacts {
176173
}
177174

178175
if (!payload.audienceId) {
179-
const data = await this.resend.delete<RemoveContactsResponseSuccess>(
176+
return this.resend.delete<RemoveContactsResponseSuccess>(
180177
`/contacts/${payload?.email ? payload?.email : payload?.id}`,
181178
);
182-
return data;
183179
}
184180

185-
const data = await this.resend.delete<RemoveContactsResponseSuccess>(
186-
`/audiences/${payload.audienceId}/contacts/${
187-
payload?.email ? payload?.email : payload?.id
181+
return this.resend.delete<RemoveContactsResponseSuccess>(
182+
`/audiences/${payload.audienceId}/contacts/${payload?.email ? payload?.email : payload?.id
188183
}`,
189184
);
190-
191-
return data;
192185
}
193186
}

src/contacts/segments/contact-segments.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ describe('ContactSegments', () => {
139139
"name": "missing_required_field",
140140
"statusCode": null,
141141
},
142+
"headers": null,
142143
}
143144
`);
144145
});
@@ -223,6 +224,7 @@ describe('ContactSegments', () => {
223224
"name": "missing_required_field",
224225
"statusCode": null,
225226
},
227+
"headers": null,
226228
}
227229
`);
228230
});
@@ -311,6 +313,7 @@ describe('ContactSegments', () => {
311313
"name": "missing_required_field",
312314
"statusCode": null,
313315
},
316+
"headers": null,
314317
}
315318
`);
316319
});

src/contacts/segments/contact-segments.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export class ContactSegments {
2525
if (!options.contactId && !options.email) {
2626
return {
2727
data: null,
28+
headers: null,
2829
error: {
2930
message: 'Missing `id` or `email` field.',
3031
statusCode: null,
@@ -49,6 +50,7 @@ export class ContactSegments {
4950
if (!options.contactId && !options.email) {
5051
return {
5152
data: null,
53+
headers: null,
5254
error: {
5355
message: 'Missing `id` or `email` field.',
5456
statusCode: null,
@@ -69,6 +71,7 @@ export class ContactSegments {
6971
if (!options.contactId && !options.email) {
7072
return {
7173
data: null,
74+
headers: null,
7275
error: {
7376
message: 'Missing `id` or `email` field.',
7477
statusCode: null,

src/contacts/topics/contact-topics.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ describe('ContactTopics', () => {
150150
"name": "missing_required_field",
151151
"statusCode": null,
152152
},
153+
"headers": null,
153154
}
154155
`);
155156
});
@@ -313,6 +314,7 @@ describe('ContactTopics', () => {
313314
"name": "missing_required_field",
314315
"statusCode": null,
315316
},
317+
"headers": null,
316318
}
317319
`);
318320
});

src/contacts/topics/contact-topics.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export class ContactTopics {
2020
if (!payload.id && !payload.email) {
2121
return {
2222
data: null,
23+
headers: null,
2324
error: {
2425
message: 'Missing `id` or `email` field.',
2526
statusCode: null,
@@ -29,12 +30,10 @@ export class ContactTopics {
2930
}
3031

3132
const identifier = payload.email ? payload.email : payload.id;
32-
const data = await this.resend.patch<UpdateContactTopicsResponseSuccess>(
33+
return this.resend.patch<UpdateContactTopicsResponseSuccess>(
3334
`/contacts/${identifier}/topics`,
3435
payload.topics,
3536
);
36-
37-
return data;
3837
}
3938

4039
async list(
@@ -43,6 +42,7 @@ export class ContactTopics {
4342
if (!options.id && !options.email) {
4443
return {
4544
data: null,
45+
headers: null,
4646
error: {
4747
message: 'Missing `id` or `email` field.',
4848
statusCode: null,
@@ -57,7 +57,6 @@ export class ContactTopics {
5757
? `/contacts/${identifier}/topics?${queryString}`
5858
: `/contacts/${identifier}/topics`;
5959

60-
const data = await this.resend.get<ListContactTopicsResponseSuccess>(url);
61-
return data;
60+
return this.resend.get<ListContactTopicsResponseSuccess>(url);
6261
}
6362
}

src/templates/chainable-template-result.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ export class ChainableTemplateResult<
3030
if (error) {
3131
return {
3232
data: null,
33+
headers: null,
3334
error,
3435
};
3536
}
36-
const publishResult = await this.publishFn(data.id);
37-
return publishResult;
37+
return this.publishFn(data.id);
3838
}
3939
}

src/topics/topics.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ describe('Topics', () => {
268268
"name": "missing_required_field",
269269
"statusCode": null,
270270
},
271+
"headers": null,
271272
}
272273
`);
273274
});
@@ -321,6 +322,7 @@ describe('Topics', () => {
321322
"name": "missing_required_field",
322323
"statusCode": null,
323324
},
325+
"headers": null,
324326
}
325327
`);
326328
});
@@ -368,6 +370,7 @@ describe('Topics', () => {
368370
"name": "missing_required_field",
369371
"statusCode": null,
370372
},
373+
"headers": null,
371374
}
372375
`);
373376
});

0 commit comments

Comments
 (0)