11import { describe , expect , it } from 'vitest'
2- import { api , setApiConfig } from '../../src'
2+ import { api , isSuccess , setApiConfig } from '../../src'
33import { PostType } from '../../src/types/options'
44import { config } from '../config'
55
@@ -10,32 +10,30 @@ describe('posts should work', () => {
1010
1111 it ( 'share should work' , async ( ) => {
1212 const post = await api . posts . get ( PostType . ORIGINAL , id )
13- expect ( post . status ) . toBe ( 200 )
13+ expect ( isSuccess ( post ) ) . toBe ( true )
14+
1415 const shareCount = post . data . data . shareCount
1516
1617 const result = await api . posts . share (
1718 PostType . ORIGINAL ,
1819 '61b8b9d298f39200100ba010' ,
1920 'weibo'
2021 )
21- expect ( result . status ) . toBe ( 200 )
22- expect ( result . data . success ) . toBe ( true )
22+ expect ( isSuccess ( result ) ) . toBe ( true )
2323
2424 const updatedPost = await api . posts . get ( PostType . ORIGINAL , id )
25- expect ( updatedPost . status ) . toBe ( 200 )
25+ expect ( isSuccess ( updatedPost ) ) . toBe ( true )
2626 expect ( updatedPost . data . data . shareCount ) . greaterThan ( shareCount )
2727 } )
2828
2929 it ( 'like should work' , async ( ) => {
3030 const result = await api . posts . like ( PostType . ORIGINAL , id )
31- expect ( result . status ) . toBe ( 200 )
32- expect ( result . data . success ) . toBe ( true )
31+ expect ( isSuccess ( result ) ) . toBe ( true )
3332 } )
3433
3534 it ( 'unlike should work' , async ( ) => {
3635 const result = await api . posts . unlike ( PostType . ORIGINAL , id )
37- expect ( result . status ) . toBe ( 200 )
38- expect ( result . data . success ) . toBe ( true )
36+ expect ( isSuccess ( result ) ) . toBe ( true )
3937 } )
4038} )
4139
@@ -45,8 +43,7 @@ describe('comment should work', () => {
4543 'ORIGINAL_POST' ,
4644 '61c0d39877abf80010426ba3'
4745 )
48- expect ( result . status ) . toBe ( 200 )
49- expect ( result . data . success ) . toBe ( true )
46+ expect ( isSuccess ( result ) ) . toBe ( true )
5047 expect ( result . data . data . length ) . greaterThan ( 0 )
5148 } )
5249
@@ -55,17 +52,15 @@ describe('comment should work', () => {
5552 'ORIGINAL_POST' ,
5653 '61c04361d8c958001025e772'
5754 )
58- expect ( result . status ) . toBe ( 200 )
59- expect ( result . data . success ) . toBe ( true )
55+ expect ( isSuccess ( result ) ) . toBe ( true )
6056 } )
6157
6258 it ( 'unlike should work' , async ( ) => {
6359 const result = await api . comments . unlike (
6460 'ORIGINAL_POST' ,
6561 '61c04361d8c958001025e772'
6662 )
67- expect ( result . status ) . toBe ( 200 )
68- expect ( result . data . success ) . toBe ( true )
63+ expect ( isSuccess ( result ) ) . toBe ( true )
6964 } )
7065} )
7166
@@ -75,12 +70,11 @@ describe('new post should work', () => {
7570 it ( 'create should work' , async ( ) => {
7671 const result = await api . posts . create (
7772 PostType . ORIGINAL ,
78- `Test For Jike-SDK. 不要评论~请忽略~ \n\n${ Math . random ( ) } ` ,
73+ `Test Post. \n\n${ Math . random ( ) } ` ,
7974 /** 悄悄话 */
8075 { topicId : '5be41ae2a666dd00172d6072' }
8176 )
82- expect ( result . status ) . toBe ( 200 )
83- expect ( result . data . success ) . toBe ( true )
77+ expect ( isSuccess ( result ) ) . toBe ( true )
8478 expect ( result . data . toast ) . toBe ( '发送成功' )
8579 expect ( result . data . data . id ) . a ( 'string' )
8680 id = result . data . data . id
@@ -92,16 +86,14 @@ describe('new post should work', () => {
9286 id ,
9387 `测试评论${ Math . random ( ) } `
9488 )
95- expect ( result . status ) . toBe ( 200 )
96- expect ( result . data . success ) . toBe ( true )
89+ expect ( isSuccess ( result ) ) . toBe ( true )
9790 expect ( result . data . toast ) . toBe ( '发送成功' )
9891 expect ( result . data . data . id ) . a ( 'string' )
9992 } )
10093
10194 it ( 'remove should work' , async ( ) => {
10295 const result = await api . posts . remove ( PostType . ORIGINAL , id )
103- expect ( result . status ) . toBe ( 200 )
104- expect ( result . data . success ) . toBe ( true )
96+ expect ( isSuccess ( result ) ) . toBe ( true )
10597 expect ( result . data . toast ) . toBe ( '删除成功' )
10698 } )
10799} )
0 commit comments