| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- import test from 'node:test';
- import assert from 'node:assert/strict';
- import {
- extractLatestXiaohongshuFansCount,
- extractXiaohongshuProfileInfo,
- } from '../src/utils/xiaohongshu.js';
- test('extracts profile info from creator personal_info snake_case response', () => {
- const profile = extractXiaohongshuProfileInfo({
- data: {
- name: 'AAA',
- avatar: 'https://example.test/avatar.jpg',
- red_num: '63535021536',
- fans_count: 1288,
- note_count: 19,
- },
- });
- assert.deepEqual(profile, {
- name: 'AAA',
- avatar: 'https://example.test/avatar.jpg',
- redNum: '63535021536',
- userId: undefined,
- fansCount: 1288,
- worksCount: 19,
- });
- });
- test('extracts profile info from creator storage camelCase response', () => {
- const profile = extractXiaohongshuProfileInfo({
- userName: 'O_O',
- userAvatar: 'https://example.test/camel.jpg',
- redId: '495513171',
- fansCount: '1.2万',
- notes: '20',
- });
- assert.deepEqual(profile, {
- name: 'O_O',
- avatar: 'https://example.test/camel.jpg',
- redNum: '495513171',
- userId: undefined,
- fansCount: 12000,
- worksCount: 20,
- });
- });
- test('extracts profile info from nested creator profile response', () => {
- const profile = extractXiaohongshuProfileInfo({
- data: {
- core_user_info: {
- nickName: 'Nested Name',
- avatarUrl: 'https://example.test/nested.jpg',
- redId: 'nested_123',
- followers_count: '2,345',
- },
- },
- });
- assert.deepEqual(profile, {
- name: 'Nested Name',
- avatar: 'https://example.test/nested.jpg',
- redNum: 'nested_123',
- userId: undefined,
- fansCount: 2345,
- worksCount: undefined,
- });
- });
- test('extracts latest fans count from overall_new response', () => {
- const count = extractLatestXiaohongshuFansCount({
- data: {
- thirty: {
- fans_list: [
- { date: 1777190400000, count: 110 },
- { date: 1777276800000, count: '1,234' },
- ],
- },
- },
- });
- assert.equal(count, 1234);
- });
|