Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(backend-core): Add public_metadata to invitation create API #85

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
36 changes: 36 additions & 0 deletions packages/backend-core/src/__tests__/apis/InvitationApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,42 @@ test('createInvitation() accepts a redirectUrl', async () => {
);
});

test('createInvitation() accepts publicMetadata', async () => {
const emailAddress = 'test@example.com';
const publicMetadata = {
hello: 'world',
};
const resJSON = {
object: 'invitation',
id: 'inv_randomid',
email_address: emailAddress,
public_metadata: publicMetadata,
created_at: 1611948436,
updated_at: 1611948436,
};

nock('https://api.clerk.dev')
.post('/v1/invitations', {
email_address: emailAddress,
public_metadata: publicMetadata,
})
.reply(200, resJSON);

const invitation = await TestBackendAPIClient.invitations.createInvitation({
emailAddress,
publicMetadata,
});
expect(invitation).toEqual(
new Invitation({
id: resJSON.id,
emailAddress,
publicMetadata,
createdAt: resJSON.created_at,
updatedAt: resJSON.updated_at,
})
);
});

test('revokeInvitation() revokes an invitation', async () => {
const id = 'inv_randomid';
const resJSON = {
Expand Down
1 change: 1 addition & 0 deletions packages/backend-core/src/api/collection/InvitationApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const basePath = '/invitations';
type CreateParams = {
emailAddress: string;
redirectUrl?: string;
publicMetadata?: Record<string, unknown>;
};

export class InvitationApi extends AbstractApi {
Expand Down
2 changes: 1 addition & 1 deletion packages/backend-core/src/api/resources/Invitation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface InvitationPayload extends InvitationProps {}
export interface Invitation extends InvitationPayload {}

export class Invitation {
static attributes = ['id', 'emailAddress', 'createdAt', 'updatedAt'];
static attributes = ['id', 'emailAddress', 'publicMetadata', 'createdAt', 'updatedAt'];

static defaults = [];

Expand Down
1 change: 1 addition & 0 deletions packages/backend-core/src/api/resources/Props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export interface IdentificationLinkProps extends ClerkProps {

export interface InvitationProps extends ClerkProps {
emailAddress: string;
publicMetadata?: Record<string, unknown>;
createdAt: number;
updatedAt: number;
}
Expand Down