Skip to content

Commit

Permalink
fix: Fix email confirmation endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
neet committed Apr 8, 2023
1 parent df5a307 commit fb23044
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/mastodon/v1/repositories/email-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Http } from '../../../http';
import type { Logger } from '../../../logger';

export interface CreateConfirmationParams {
/** If provided, updates the unconfirmed user’s email before resending the confirmation email. */
readonly email?: string;
}

Expand All @@ -13,7 +14,15 @@ export class EmailRepository {
readonly logger?: Logger,
) {}

/**
* Resend confirmation email
* @param params Form data parameters
* @returns Empty object
* @see https://docs.joinmastodon.org/methods/emails/#confirmation
*/
createConfirmation(params?: CreateConfirmationParams): Promise<void> {
return this.http.post('/api/v1/email/confirmations', params);
return this.http.post('/api/v1/emails/confirmations', params, {
headers: { 'Content-Type': 'multipart/form-data' },
});
}
}
24 changes: 24 additions & 0 deletions tests/v1/emails.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import crypto from 'node:crypto';

import { login } from '../../src';

it('can create a confirmation', async () => {
const username = crypto.randomBytes(8).toString('hex');
let email = `${username}@example.com`;

const token = await admin.v1.accounts.create({
username,
email,
password: 'password',
agreement: true,
locale: 'en',
});

const client = await login({
url: __misc__.url,
accessToken: token.accessToken,
});

email = `${username}@example2.com`;
await client.v1.emails.createConfirmation({ email });
});

0 comments on commit fb23044

Please sign in to comment.