|
| 1 | +// |
| 2 | + |
| 3 | +import { insert_nordPass_authenticator } from "@~/identite-proconnect.database/seed/authenticators/nordPass"; |
| 4 | +import { insert_1Password_authenticator } from "@~/identite-proconnect.database/seed/authenticators/onePassword"; |
| 5 | +import { create_pink_diamond_user } from "@~/identite-proconnect.database/seed/unicorn"; |
| 6 | +import { |
| 7 | + empty_database, |
| 8 | + migrate, |
| 9 | + pg, |
| 10 | +} from "@~/identite-proconnect.database/testing"; |
| 11 | +import { beforeAll, beforeEach, expect, test } from "bun:test"; |
| 12 | +import { get_authenticators_by_user_id } from "./get_authenticators_by_user_id"; |
| 13 | + |
| 14 | +// |
| 15 | + |
| 16 | +beforeAll(migrate); |
| 17 | +beforeEach(empty_database); |
| 18 | + |
| 19 | +test("should returns one authenticator", async () => { |
| 20 | + const pink_diamond_user_id = await create_pink_diamond_user(pg); |
| 21 | + |
| 22 | + await insert_1Password_authenticator(pg, pink_diamond_user_id); |
| 23 | + |
| 24 | + const authenticators = await get_authenticators_by_user_id(pg, { |
| 25 | + id: pink_diamond_user_id, |
| 26 | + }); |
| 27 | + |
| 28 | + expect(authenticators).toHaveLength(1); |
| 29 | +}); |
| 30 | + |
| 31 | +test("should returns two authenticators & structure of authenticators", async () => { |
| 32 | + const pink_diamond_user_id = await create_pink_diamond_user(pg); |
| 33 | + |
| 34 | + await insert_1Password_authenticator(pg, pink_diamond_user_id); |
| 35 | + await insert_nordPass_authenticator(pg, pink_diamond_user_id); |
| 36 | + |
| 37 | + const authenticators = await get_authenticators_by_user_id(pg, { |
| 38 | + id: pink_diamond_user_id, |
| 39 | + }); |
| 40 | + |
| 41 | + expect(authenticators).toHaveLength(2); |
| 42 | + expect(authenticators).toEqual([ |
| 43 | + { |
| 44 | + display_name: "1Password", |
| 45 | + created_at: expect.any(String), |
| 46 | + last_used_at: expect.any(String), |
| 47 | + usage_count: expect.any(Number), |
| 48 | + }, |
| 49 | + { |
| 50 | + display_name: "NordPass", |
| 51 | + created_at: expect.any(String), |
| 52 | + last_used_at: expect.any(String), |
| 53 | + usage_count: expect.any(Number), |
| 54 | + }, |
| 55 | + ]); |
| 56 | +}); |
| 57 | + |
| 58 | +test("should returns zero authenticator", async () => { |
| 59 | + const pink_diamond_user_id = await create_pink_diamond_user(pg); |
| 60 | + |
| 61 | + const authenticators = await get_authenticators_by_user_id(pg, { |
| 62 | + id: pink_diamond_user_id, |
| 63 | + }); |
| 64 | + |
| 65 | + expect(authenticators).toHaveLength(0); |
| 66 | +}); |
0 commit comments