Skip to content

Commit

Permalink
Add test for person email pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
caebr committed Apr 28, 2020
1 parent 6382df5 commit ed77992
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
48 changes: 48 additions & 0 deletions src/app/presence-control/utils/person-email-pipe.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { PersonEmailPipe } from './person-email-pipe';
import { buildPersonWithEmails } from '../../../spec-builders';

describe('person email pipe', () => {
let personEmailPipe: PersonEmailPipe;

beforeEach(() => {
personEmailPipe = new PersonEmailPipe();
});

it('should return null for a person without any email set', () => {
expect(personEmailPipe.transform(buildPersonWithEmails(12345))).toBeNull();
});

it('should return the first email address if all options have values', () => {
expect(
personEmailPipe.transform(
buildPersonWithEmails(
12345,
'first@email.ch',
'second@email.ch',
'third@email.ch'
)
)
).toBe('first@email.ch');
});

it('should return the email address with a value ', () => {
expect(
personEmailPipe.transform(
buildPersonWithEmails(12345, undefined, 'second@email.ch', undefined)
)
).toBe('second@email.ch');
});

it('should return the first email address with a value ', () => {
expect(
personEmailPipe.transform(
buildPersonWithEmails(
12345,
undefined,
'second@email.ch',
'third@email.ch'
)
)
).toBe('second@email.ch');
});
});
6 changes: 3 additions & 3 deletions src/spec-builders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,10 @@ export function buildPersonWithEmails(
displayEmail?: string,
email?: string,
email2?: string
) {
): Person {
const person = buildPerson(id);
person.DisplayEmail = displayEmail || null;
person.Email = email || null;
person.Email2 = email2 || null;
person.Email = email;
person.Email2 = email2;
return person;
}

0 comments on commit ed77992

Please sign in to comment.