Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanarnault committed Aug 12, 2024
1 parent b2b634b commit 49fe6ee
Showing 1 changed file with 80 additions and 56 deletions.
136 changes: 80 additions & 56 deletions src/tests/supabase/functions/postmark.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getExpectedAuthorization } from '../../../../supabase/functions/postmark/getExpectedAuthorization.js';
import { extractMailContactData } from '../../../../supabase/functions/postmark/extractMailContactData.js';
import { getExpectedAuthorization } from '../../../../supabase/functions/postmark/getExpectedAuthorization.js';

describe('getExpectedAuthorization', () => {
it('should return the expected Authorization header from provided user and password', () => {
Expand All @@ -16,15 +16,17 @@ describe('extractMailContactData', () => {
Name: 'Firstname Lastname',
},
]);
expect(result).toEqual({
firstName: 'Firstname',
lastName: 'Lastname',
email: '[email protected]',
domain: 'marmelab.com',
});
expect(result).toEqual([
{
firstName: 'Firstname',
lastName: 'Lastname',
email: '[email protected]',
domain: 'marmelab.com',
},
]);
});

it('should ignore extra recipients', () => {
it('should support extra recipients', () => {
const result = extractMailContactData([
{
Email: '[email protected]',
Expand All @@ -35,12 +37,20 @@ describe('extractMailContactData', () => {
Name: 'John Doe',
},
]);
expect(result).toEqual({
firstName: 'Firstname',
lastName: 'Lastname',
email: '[email protected]',
domain: 'marmelab.com',
});
expect(result).toEqual([
{
firstName: 'Firstname',
lastName: 'Lastname',
email: '[email protected]',
domain: 'marmelab.com',
},
{
firstName: 'John',
lastName: 'Doe',
email: '[email protected]',
domain: 'marmelab.com',
},
]);
});

it('should use a single word name as last name', () => {
Expand All @@ -50,12 +60,14 @@ describe('extractMailContactData', () => {
Name: 'Name',
},
]);
expect(result).toEqual({
firstName: '',
lastName: 'Name',
email: '[email protected]',
domain: 'marmelab.com',
});
expect(result).toEqual([
{
firstName: '',
lastName: 'Name',
email: '[email protected]',
domain: 'marmelab.com',
},
]);
});

it('should support multi word last name', () => {
Expand All @@ -65,12 +77,14 @@ describe('extractMailContactData', () => {
Name: 'Multi Word Name',
},
]);
expect(result).toEqual({
firstName: 'Multi',
lastName: 'Word Name',
email: '[email protected]',
domain: 'marmelab.com',
});
expect(result).toEqual([
{
firstName: 'Multi',
lastName: 'Word Name',
email: '[email protected]',
domain: 'marmelab.com',
},
]);
});

it('should support multiple @ in email', () => {
Expand All @@ -81,12 +95,14 @@ describe('extractMailContactData', () => {
Name: 'John Doe',
},
]);
expect(result).toEqual({
firstName: 'John',
lastName: 'Doe',
email: '"john@doe"@marmelab.com',
domain: 'marmelab.com',
});
expect(result).toEqual([
{
firstName: 'John',
lastName: 'Doe',
email: '"john@doe"@marmelab.com',
domain: 'marmelab.com',
},
]);
});

it('should use first part of email when Name is empty', () => {
Expand All @@ -96,12 +112,14 @@ describe('extractMailContactData', () => {
Name: '',
},
]);
expect(result).toEqual({
firstName: 'john',
lastName: 'doe',
email: '[email protected]',
domain: 'marmelab.com',
});
expect(result).toEqual([
{
firstName: 'john',
lastName: 'doe',
email: '[email protected]',
domain: 'marmelab.com',
},
]);
});

it('should use first part of email when Name is empty and support single word', () => {
Expand All @@ -111,12 +129,14 @@ describe('extractMailContactData', () => {
Name: '',
},
]);
expect(result).toEqual({
firstName: '',
lastName: 'john',
email: '[email protected]',
domain: 'marmelab.com',
});
expect(result).toEqual([
{
firstName: '',
lastName: 'john',
email: '[email protected]',
domain: 'marmelab.com',
},
]);
});

it('should use first part of email when Name is empty and support multiple words', () => {
Expand All @@ -126,12 +146,14 @@ describe('extractMailContactData', () => {
Name: '',
},
]);
expect(result).toEqual({
firstName: 'john',
lastName: 'doe multi',
email: '[email protected]',
domain: 'marmelab.com',
});
expect(result).toEqual([
{
firstName: 'john',
lastName: 'doe multi',
email: '[email protected]',
domain: 'marmelab.com',
},
]);
});

it('should support empty Name and multiple @ in email', () => {
Expand All @@ -142,11 +164,13 @@ describe('extractMailContactData', () => {
Name: '',
},
]);
expect(result).toEqual({
firstName: '"john',
lastName: 'doe"',
email: '"john@doe"@marmelab.com',
domain: 'marmelab.com',
});
expect(result).toEqual([
{
firstName: '"john',
lastName: 'doe"',
email: '"john@doe"@marmelab.com',
domain: 'marmelab.com',
},
]);
});
});

0 comments on commit 49fe6ee

Please sign in to comment.