Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 56 additions & 68 deletions src/contacts/topics/contact-topics.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import createFetchMock from 'vitest-fetch-mock';
import { Resend } from '../../resend';
import { mockSuccessResponse } from '../../test-utils/mock-fetch';
import type {
GetContactTopicsOptions,
GetContactTopicsResponseSuccess,
} from './interfaces/get-contact-topics.interface';
ListContactTopicsOptions,
ListContactTopicsResponseSuccess,
} from './interfaces/list-contact-topics.interface';
import type {
UpdateContactTopicsOptions,
UpdateContactTopicsResponseSuccess,
Expand Down Expand Up @@ -174,31 +174,28 @@ describe('ContactTopics', () => {
});
});

describe('get', () => {
describe('list', () => {
it('gets contact topics by email', async () => {
const options: GetContactTopicsOptions = {
const options: ListContactTopicsOptions = {
email: '[email protected]',
};
const response: GetContactTopicsResponseSuccess = {
const response: ListContactTopicsResponseSuccess = {
has_more: false,
object: 'list',
data: {
email: '[email protected]',
topics: [
{
id: 'c7e1e488-ae2c-4255-a40c-a4db3af7ed0b',
name: 'Test Topic',
description: 'This is a test topic',
subscription: 'opt_in',
},
{
id: 'another-topic-id',
name: 'Another Topic',
description: null,
subscription: 'opt_out',
},
],
},
data: [
{
id: 'c7e1e488-ae2c-4255-a40c-a4db3af7ed0b',
name: 'Test Topic',
description: 'This is a test topic',
subscription: 'opt_in',
},
{
id: 'another-topic-id',
name: 'Another Topic',
description: null,
subscription: 'opt_out',
},
],
};

mockSuccessResponse(response, {
Expand All @@ -207,27 +204,24 @@ describe('ContactTopics', () => {

const resend = new Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
await expect(
resend.contacts.topics.get(options),
resend.contacts.topics.list(options),
).resolves.toMatchInlineSnapshot(`
{
"data": {
"data": {
"email": "[email protected]",
"topics": [
{
"description": "This is a test topic",
"id": "c7e1e488-ae2c-4255-a40c-a4db3af7ed0b",
"name": "Test Topic",
"subscription": "opt_in",
},
{
"description": null,
"id": "another-topic-id",
"name": "Another Topic",
"subscription": "opt_out",
},
],
},
"data": [
{
"description": "This is a test topic",
"id": "c7e1e488-ae2c-4255-a40c-a4db3af7ed0b",
"name": "Test Topic",
"subscription": "opt_in",
},
{
"description": null,
"id": "another-topic-id",
"name": "Another Topic",
"subscription": "opt_out",
},
],
"has_more": false,
"object": "list",
},
Expand All @@ -237,23 +231,20 @@ describe('ContactTopics', () => {
});

it('gets contact topics by ID', async () => {
const options: GetContactTopicsOptions = {
const options: ListContactTopicsOptions = {
id: '3d4a472d-bc6d-4dd2-aa9d-d3d50ce87223',
};
const response: GetContactTopicsResponseSuccess = {
const response: ListContactTopicsResponseSuccess = {
has_more: false,
object: 'list',
data: {
email: '[email protected]',
topics: [
{
id: 'c7e1e488-ae2c-4255-a40c-a4db3af7ed0b',
name: 'Test Topic',
description: 'This is a test topic',
subscription: 'opt_in',
},
],
},
data: [
{
id: 'c7e1e488-ae2c-4255-a40c-a4db3af7ed0b',
name: 'Test Topic',
description: 'This is a test topic',
subscription: 'opt_in',
},
],
};

mockSuccessResponse(response, {
Expand All @@ -262,21 +253,18 @@ describe('ContactTopics', () => {

const resend = new Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
await expect(
resend.contacts.topics.get(options),
resend.contacts.topics.list(options),
).resolves.toMatchInlineSnapshot(`
{
"data": {
"data": {
"email": "[email protected]",
"topics": [
{
"description": "This is a test topic",
"id": "c7e1e488-ae2c-4255-a40c-a4db3af7ed0b",
"name": "Test Topic",
"subscription": "opt_in",
},
],
},
"data": [
{
"description": "This is a test topic",
"id": "c7e1e488-ae2c-4255-a40c-a4db3af7ed0b",
"name": "Test Topic",
"subscription": "opt_in",
},
],
"has_more": false,
"object": "list",
},
Expand All @@ -289,8 +277,8 @@ describe('ContactTopics', () => {
const options = {};
const resend = new Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');

const result = resend.contacts.topics.get(
options as GetContactTopicsOptions,
const result = resend.contacts.topics.list(
options as ListContactTopicsOptions,
);

await expect(result).resolves.toMatchInlineSnapshot(`
Expand Down
16 changes: 8 additions & 8 deletions src/contacts/topics/contact-topics.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { buildPaginationQuery } from '../../common/utils/build-pagination-query';
import type { Resend } from '../../resend';
import type {
GetContactTopicsOptions,
GetContactTopicsResponse,
GetContactTopicsResponseSuccess,
} from './interfaces/get-contact-topics.interface';
ListContactTopicsOptions,
ListContactTopicsResponse,
ListContactTopicsResponseSuccess,
} from './interfaces/list-contact-topics.interface';
import type {
UpdateContactTopicsOptions,
UpdateContactTopicsResponse,
Expand Down Expand Up @@ -37,9 +37,9 @@ export class ContactTopics {
return data;
}

async get(
options: GetContactTopicsOptions,
): Promise<GetContactTopicsResponse> {
async list(
options: ListContactTopicsOptions,
): Promise<ListContactTopicsResponse> {
if (!options.id && !options.email) {
return {
data: null,
Expand All @@ -57,7 +57,7 @@ export class ContactTopics {
? `/contacts/${identifier}/topics?${queryString}`
: `/contacts/${identifier}/topics`;

const data = await this.resend.get<GetContactTopicsResponseSuccess>(url);
const data = await this.resend.get<ListContactTopicsResponseSuccess>(url);
return data;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import type {
} from '../../../common/interfaces/pagination-options.interface';
import type { ErrorResponse } from '../../../interfaces';

interface GetContactTopicsBaseOptions {
interface ListContactTopicsBaseOptions {
id?: string;
email?: string;
}

export type GetContactTopicsOptions = GetContactTopicsBaseOptions &
export type ListContactTopicsOptions = ListContactTopicsBaseOptions &
PaginationOptions;

export interface GetContactTopicsRequestOptions extends GetOptions {}
export interface ListContactTopicsRequestOptions extends GetOptions {}

export interface ContactTopic {
id: string;
Expand All @@ -22,17 +22,11 @@ export interface ContactTopic {
subscription: 'opt_in' | 'opt_out';
}

export type GetContactTopicsResponseSuccess = PaginatedData<{
email: string;
topics: ContactTopic[];
}>;
export type ListContactTopicsResponseSuccess = PaginatedData<ContactTopic[]>;

export type GetContactTopicsResponse =
export type ListContactTopicsResponse =
| {
data: PaginatedData<{
email: string;
topics: ContactTopic[];
}>;
data: ListContactTopicsResponseSuccess;
error: null;
}
| {
Expand Down
Loading