|
| 1 | +import { deserializeFactor } from './authentication-factor.serializer'; |
| 2 | +import { AuthenticationFactorResponse } from '../interfaces/authentication-factor.interface'; |
| 3 | +import listFactorsFixture from '../fixtures/list-factors.json'; |
| 4 | + |
| 5 | +describe('deserializeFactor', () => { |
| 6 | + it('deserializes totp, sms, and generic_otp factors', () => { |
| 7 | + const factors = listFactorsFixture.data.map((factor) => |
| 8 | + deserializeFactor(factor as AuthenticationFactorResponse), |
| 9 | + ); |
| 10 | + |
| 11 | + expect(factors).toStrictEqual([ |
| 12 | + { |
| 13 | + object: 'authentication_factor', |
| 14 | + id: 'auth_factor_1234', |
| 15 | + createdAt: '2022-03-15T20:39:19.892Z', |
| 16 | + updatedAt: '2022-03-15T20:39:19.892Z', |
| 17 | + type: 'totp', |
| 18 | + totp: { |
| 19 | + issuer: 'WorkOS', |
| 20 | + user: 'some_user', |
| 21 | + }, |
| 22 | + userId: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS', |
| 23 | + }, |
| 24 | + { |
| 25 | + object: 'authentication_factor', |
| 26 | + id: 'auth_factor_5678', |
| 27 | + createdAt: '2022-03-15T20:39:19.892Z', |
| 28 | + updatedAt: '2022-03-15T20:39:19.892Z', |
| 29 | + type: 'sms', |
| 30 | + sms: { |
| 31 | + phoneNumber: '+15555555555', |
| 32 | + }, |
| 33 | + userId: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS', |
| 34 | + }, |
| 35 | + { |
| 36 | + object: 'authentication_factor', |
| 37 | + id: 'auth_factor_9012', |
| 38 | + createdAt: '2022-03-15T20:39:19.892Z', |
| 39 | + updatedAt: '2022-03-15T20:39:19.892Z', |
| 40 | + type: 'generic_otp', |
| 41 | + userId: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS', |
| 42 | + }, |
| 43 | + ]); |
| 44 | + }); |
| 45 | +}); |
0 commit comments