1- import { expect } from 'chai'
1+ import { beforeEach , describe , expect , test } from 'vitest'
2+ import { makeApi } from '../server'
3+ let api , mockApi
24
35import createStubContext from '../stubs/context'
46import createJsonapiModule from '../utils/createJsonapiModule'
@@ -9,14 +11,15 @@ describe('deleteRelated', function () {
911 let normWidget1 , jsonWidget1 , jsonapiModule , stubContext
1012
1113 beforeEach ( function ( ) {
14+ [ api , mockApi ] = makeApi ( )
1215 normWidget1 = createNormWidget1 ( )
1316 jsonWidget1 = createJsonWidget1 ( )
1417
15- jsonapiModule = createJsonapiModule ( this . api )
18+ jsonapiModule = createJsonapiModule ( api )
1619 stubContext = createStubContext ( jsonapiModule )
1720 } )
1821
19- it ( 'Should throw an error if passed an object with no type or id' , async function ( ) {
22+ test ( 'Should throw an error if passed an object with no type or id' , async function ( ) {
2023 try {
2124 await jsonapiModule . actions . deleteRelated ( stubContext , { _jv : { } } )
2225 throw 'Should have thrown an error (no id)'
@@ -25,7 +28,7 @@ describe('deleteRelated', function () {
2528 }
2629 } )
2730
28- it ( 'Should throw an error if passed an object with no relationships' , async function ( ) {
31+ test ( 'Should throw an error if passed an object with no relationships' , async function ( ) {
2932 try {
3033 await jsonapiModule . actions . deleteRelated ( stubContext , { _jv : { type : 'widget' , id : 1 } } )
3134 throw 'Should have thrown an error (no relationships)'
@@ -34,24 +37,24 @@ describe('deleteRelated', function () {
3437 }
3538 } )
3639
37- it ( 'should make a delete request for the object passed in.' , async function ( ) {
38- this . mockApi . onDelete ( ) . replyOnce ( 204 )
39- this . mockApi . onGet ( ) . replyOnce ( 200 , { data : jsonWidget1 } )
40+ test ( 'should make a delete request for the object passed in.' , async function ( ) {
41+ mockApi . onDelete ( ) . replyOnce ( 204 )
42+ mockApi . onGet ( ) . replyOnce ( 200 , { data : jsonWidget1 } )
4043
4144 const rel = { data : { type : 'widget' , id : '2' } }
4245 normWidget1 [ '_jv' ] [ 'relationships' ] = { widgets : rel }
4346
4447 await jsonapiModule . actions . deleteRelated ( stubContext , normWidget1 )
4548 // Expect a delete call to rel url, with rel payload, then get object to update store
46- expect ( this . mockApi . history . delete [ 0 ] . url ) . to . equal ( 'widget/1/relationships/widgets' )
47- expect ( this . mockApi . history . delete [ 0 ] . data ) . to . deep . equal ( JSON . stringify ( rel ) )
48- expect ( this . mockApi . history . get [ 0 ] . params ) . to . have . property ( 'include' )
49- expect ( this . mockApi . history . get [ 0 ] . url ) . to . equal ( 'widget/1' )
49+ expect ( mockApi . history . delete [ 0 ] . url ) . to . equal ( 'widget/1/relationships/widgets' )
50+ expect ( mockApi . history . delete [ 0 ] . data ) . to . deep . equal ( JSON . stringify ( rel ) )
51+ expect ( mockApi . history . get [ 0 ] . params ) . to . have . property ( 'include' )
52+ expect ( mockApi . history . get [ 0 ] . url ) . to . equal ( 'widget/1' )
5053 } )
5154
52- it ( 'should make a delete request for the object passed in.' , async function ( ) {
53- this . mockApi . onDelete ( ) . replyOnce ( 204 )
54- this . mockApi . onGet ( ) . replyOnce ( 200 , { data : jsonWidget1 } )
55+ test ( 'should make a delete request for the object passed in.' , async function ( ) {
56+ mockApi . onDelete ( ) . replyOnce ( 204 )
57+ mockApi . onGet ( ) . replyOnce ( 200 , { data : jsonWidget1 } )
5558
5659 const rel = { data : { type : 'widget' , id : '2' } }
5760 normWidget1 [ '_jv' ] [ 'relationships' ] = { widgets : rel }
@@ -60,33 +63,33 @@ describe('deleteRelated', function () {
6063
6164 await jsonapiModule . actions . deleteRelated ( stubContext , normWidget1 )
6265 // Expect a delete call to rel url, with rel payload, then get object to update store
63- expect ( this . mockApi . history . delete [ 0 ] . url ) . to . equal ( 'widget/1/relationships/widgets' )
64- expect ( this . mockApi . history . delete [ 0 ] . data ) . to . deep . equal ( JSON . stringify ( rel ) )
65- expect ( this . mockApi . history . get [ 0 ] . params ) . to . not . have . property ( 'include' )
66- expect ( this . mockApi . history . get [ 0 ] . url ) . to . equal ( 'widget/1' )
66+ expect ( mockApi . history . delete [ 0 ] . url ) . to . equal ( 'widget/1/relationships/widgets' )
67+ expect ( mockApi . history . delete [ 0 ] . data ) . to . deep . equal ( JSON . stringify ( rel ) )
68+ expect ( mockApi . history . get [ 0 ] . params ) . to . not . have . property ( 'include' )
69+ expect ( mockApi . history . get [ 0 ] . url ) . to . equal ( 'widget/1' )
6770 } )
6871
69- it ( 'should handle multiple relationships' , async function ( ) {
70- this . mockApi . onDelete ( ) . reply ( 204 )
71- this . mockApi . onGet ( ) . replyOnce ( 200 , { data : jsonWidget1 } )
72+ test ( 'should handle multiple relationships' , async function ( ) {
73+ mockApi . onDelete ( ) . reply ( 204 )
74+ mockApi . onGet ( ) . replyOnce ( 200 , { data : jsonWidget1 } )
7275
7376 const rel1 = { data : { type : 'widget' , id : '2' } }
7477 const rel2 = { data : { type : 'doohickey' , id : '3' } }
7578 normWidget1 [ '_jv' ] [ 'relationships' ] = { widgets : rel1 , doohickeys : rel2 }
7679
7780 await jsonapiModule . actions . deleteRelated ( stubContext , normWidget1 )
78- expect ( this . mockApi . history . delete [ 0 ] . url ) . to . equal ( 'widget/1/relationships/widgets' )
79- expect ( this . mockApi . history . delete [ 0 ] . data ) . to . deep . equal ( JSON . stringify ( rel1 ) )
80- expect ( this . mockApi . history . delete [ 1 ] . url ) . to . equal ( 'widget/1/relationships/doohickeys' )
81- expect ( this . mockApi . history . delete [ 1 ] . data ) . to . deep . equal ( JSON . stringify ( rel2 ) )
82- expect ( this . mockApi . history . get [ 0 ] . params ) . to . have . property ( 'include' )
83- expect ( this . mockApi . history . get [ 0 ] . url ) . to . equal ( 'widget/1' )
81+ expect ( mockApi . history . delete [ 0 ] . url ) . to . equal ( 'widget/1/relationships/widgets' )
82+ expect ( mockApi . history . delete [ 0 ] . data ) . to . deep . equal ( JSON . stringify ( rel1 ) )
83+ expect ( mockApi . history . delete [ 1 ] . url ) . to . equal ( 'widget/1/relationships/doohickeys' )
84+ expect ( mockApi . history . delete [ 1 ] . data ) . to . deep . equal ( JSON . stringify ( rel2 ) )
85+ expect ( mockApi . history . get [ 0 ] . params ) . to . have . property ( 'include' )
86+ expect ( mockApi . history . get [ 0 ] . url ) . to . equal ( 'widget/1' )
8487 // Only get the object once at end
85- expect ( this . mockApi . history . get . length ) . to . equal ( 1 )
88+ expect ( mockApi . history . get . length ) . to . equal ( 1 )
8689 } )
8790
88- it ( 'Should handle API errors (in the data)' , async function ( ) {
89- this . mockApi . onDelete ( ) . reply ( 500 )
91+ test ( 'Should handle API errors (in the data)' , async function ( ) {
92+ mockApi . onDelete ( ) . reply ( 500 )
9093
9194 const rel = { data : { type : 'widget' , id : '2' } }
9295 normWidget1 [ '_jv' ] [ 'relationships' ] = { widgets : rel }
0 commit comments