| 1 | import { AccountType } from '@yikart/common' |
| 2 | import { describe, expect, it, vi } from 'vitest' |
| 3 | import { ChannelAccountVo } from './account.vo' |
| 4 | |
| 5 | vi.mock('@yikart/mongodb', () => ({ |
| 6 | AccountStatus: { |
| 7 | NORMAL: 1, |
| 8 | ABNORMAL: 0, |
| 9 | }, |
| 10 | ClientType: { |
| 11 | WEB: 'web', |
| 12 | APP: 'app', |
| 13 | }, |
| 14 | })) |
| 15 | |
| 16 | describe('channel account vo', () => { |
| 17 | it('returns safe account table fields and strips credentials', () => { |
| 18 | const vo = ChannelAccountVo.create({ |
| 19 | id: 'account-1', |
| 20 | userId: 'user-1', |
| 21 | type: AccountType.WeChatChannels, |
| 22 | uid: 'finder-1', |
| 23 | account: 'finder_account', |
| 24 | avatar: 'https://assets.example.test/avatar.jpg', |
| 25 | nickname: 'Finder', |
| 26 | groupId: 'group-1', |
| 27 | status: 1, |
| 28 | fansCount: 100, |
| 29 | followingCount: 5, |
| 30 | readCount: 1000, |
| 31 | likeCount: 20, |
| 32 | collectCount: 3, |
| 33 | forwardCount: 2, |
| 34 | commentCount: 1, |
| 35 | workCount: 6, |
| 36 | income: 0, |
| 37 | relayAccountRef: null, |
| 38 | loginCookie: 'secret-cookie', |
| 39 | access_token: 'access-token', |
| 40 | refresh_token: 'refresh-token', |
| 41 | token: 'token', |
| 42 | }) |
| 43 | |
| 44 | expect(vo).toMatchObject({ |
| 45 | id: 'account-1', |
| 46 | userId: 'user-1', |
| 47 | fansCount: 100, |
| 48 | followingCount: 5, |
| 49 | forwardCount: 2, |
| 50 | relayAccountRef: null, |
| 51 | }) |
| 52 | expect(vo).not.toHaveProperty('loginCookie') |
| 53 | expect(vo).not.toHaveProperty('access_token') |
| 54 | expect(vo).not.toHaveProperty('refresh_token') |
| 55 | expect(vo).not.toHaveProperty('token') |
| 56 | }) |
| 57 | }) |
| 58 |