Skip to content

Commit

Permalink
feat: Add patch domain (#320)
Browse files Browse the repository at this point in the history
  • Loading branch information
bukinoshita authored Feb 10, 2024
1 parent 92b95c7 commit b60c133
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
38 changes: 37 additions & 1 deletion src/domains/domains.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from './interfaces/create-domain-options.interface';
import { ListDomainsResponseSuccess } from './interfaces/list-domains.interface';
import { RemoveDomainsResponseSuccess } from './interfaces/remove-domain.interface';
import { PatchDomainsResponseSuccess } from './interfaces/patch-domain.interface';

enableFetchMocks();

Expand Down Expand Up @@ -498,6 +499,41 @@ describe('Domains', () => {
});
});

describe('patch', () => {
it('patch domain click tracking', async () => {
const id = '5262504e-8ed7-4fac-bd16-0d4be94bc9f2';
const response: PatchDomainsResponseSuccess = {
object: 'domain',
id,
};

fetchMock.mockOnce(JSON.stringify(response), {
status: 200,
headers: {
'content-type': 'application/json',
Authorization: 'Bearer re_924b3rjh2387fbewf823',
},
});

const resend = new Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');

await expect(
resend.domains.patch({
id,
click_tracking: true,
}),
).resolves.toMatchInlineSnapshot(`
{
"data": {
"id": "5262504e-8ed7-4fac-bd16-0d4be94bc9f2",
"object": "domain",
},
"error": null,
}
`);
});
});

describe('verify', () => {
it('verifies a domain', async () => {
fetchMock.mockOnce(JSON.stringify({}), {
Expand Down Expand Up @@ -525,7 +561,7 @@ describe('Domains', () => {
it('removes a domain', async () => {
const id = '5262504e-8ed7-4fac-bd16-0d4be94bc9f2';
const response: RemoveDomainsResponseSuccess = {
id: id,
id,
};
fetchMock.mockOnce(JSON.stringify(response), {
status: 200,
Expand Down
16 changes: 16 additions & 0 deletions src/domains/domains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import {
ListDomainsResponse,
ListDomainsResponseSuccess,
} from './interfaces/list-domains.interface';
import {
PatchDomainsOptions,
PatchDomainsResponse,
PatchDomainsResponseSuccess,
} from './interfaces/patch-domain.interface';
import {
RemoveDomainsResponse,
RemoveDomainsResponseSuccess,
Expand Down Expand Up @@ -49,6 +54,17 @@ export class Domains {
return data;
}

async patch(payload: PatchDomainsOptions): Promise<PatchDomainsResponse> {
const data = await this.resend.patch<PatchDomainsResponseSuccess>(
`/domains/${payload.id}`,
{
click_tracking: payload.click_tracking,
open_tracking: payload.open_tracking,
},
);
return data;
}

async remove(id: string): Promise<RemoveDomainsResponse> {
const data = await this.resend.delete<RemoveDomainsResponseSuccess>(
`/domains/${id}`,
Expand Down
17 changes: 17 additions & 0 deletions src/domains/interfaces/patch-domain.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ErrorResponse } from '../../interfaces';
import { Domain } from './domain';

export interface PatchDomainsOptions {
id: string;
click_tracking?: boolean;
open_tracking?: boolean;
}

export type PatchDomainsResponseSuccess = Pick<Domain, 'id'> & {
object: 'domain';
};

export interface PatchDomainsResponse {
data: PatchDomainsResponseSuccess | null;
error: ErrorResponse | null;
}

0 comments on commit b60c133

Please sign in to comment.