@@ -11,7 +11,6 @@ import type {
11
11
} from './payload-types'
12
12
13
13
import payload from '../../packages/payload/src'
14
- import { mapAsync } from '../../packages/payload/src/utilities/mapAsync'
15
14
import { devUser } from '../credentials'
16
15
import { initPayloadTest } from '../helpers/configHelpers'
17
16
import { RESTClient } from '../helpers/rest'
@@ -40,7 +39,7 @@ describe('Relationships', () => {
40
39
beforeAll ( async ( ) => {
41
40
const { serverURL } = await initPayloadTest ( { __dirname, init : { local : false } } )
42
41
apiUrl = `${ serverURL } /api`
43
- client = new RESTClient ( config , { serverURL , defaultSlug : slug } )
42
+ client = new RESTClient ( config , { defaultSlug : slug , serverURL } )
44
43
await client . login ( )
45
44
46
45
const response = await fetch ( `${ apiUrl } /users/login` , {
@@ -128,8 +127,8 @@ describe('Relationships', () => {
128
127
} )
129
128
130
129
chained3 = await payload . update < ChainedRelation > ( {
131
- collection : chainedRelSlug ,
132
130
id : chained3 . id ,
131
+ collection : chainedRelSlug ,
133
132
data : {
134
133
name : 'chain3' ,
135
134
relation : chained . id ,
@@ -155,13 +154,13 @@ describe('Relationships', () => {
155
154
} )
156
155
157
156
post = await createPost ( {
158
- relationField : relation . id ,
159
- defaultAccessRelation : defaultAccessRelation . id ,
160
157
chainedRelation : chained . id ,
161
- maxDepthRelation : relation . id ,
162
- customIdRelation : customIdRelation . id ,
163
158
customIdNumberRelation : customIdNumberRelation . id ,
159
+ customIdRelation : customIdRelation . id ,
160
+ defaultAccessRelation : defaultAccessRelation . id ,
164
161
filteredRelation : filteredRelation . id ,
162
+ maxDepthRelation : relation . id ,
163
+ relationField : relation . id ,
165
164
} )
166
165
167
166
await createPost ( ) // Extra post to allow asserting totalDoc count
@@ -194,15 +193,15 @@ describe('Relationships', () => {
194
193
expect ( docAfterUpdatingRel . filteredRelation ) . toMatchObject ( { id : filteredRelation . id } )
195
194
196
195
// Attempt to update post with a now filtered relation
197
- const { status , errors } = await client . update < Post > ( {
196
+ const { errors , status } = await client . update < Post > ( {
198
197
id : post . id ,
199
198
data : { filteredRelation : filteredRelation . id } ,
200
199
} )
201
200
202
201
expect ( errors ?. [ 0 ] ) . toMatchObject ( {
203
202
name : 'ValidationError' ,
204
- message : expect . any ( String ) ,
205
203
data : expect . anything ( ) ,
204
+ message : expect . any ( String ) ,
206
205
} )
207
206
expect ( status ) . toEqual ( 400 )
208
207
} )
@@ -307,8 +306,8 @@ describe('Relationships', () => {
307
306
308
307
it ( 'should allow update removing a relationship' , async ( ) => {
309
308
const result = await client . update < Post > ( {
310
- slug,
311
309
id : post . id ,
310
+ slug,
312
311
data : {
313
312
relationField : null ,
314
313
} ,
@@ -446,8 +445,8 @@ describe('Relationships', () => {
446
445
await payload . create ( {
447
446
collection : 'screenings' ,
448
447
data : {
449
- movie : movie . id ,
450
448
name : 'Pulp Fiction Screening' ,
449
+ movie : movie . id ,
451
450
} ,
452
451
} )
453
452
} )
@@ -486,8 +485,8 @@ describe('Relationships', () => {
486
485
487
486
beforeAll ( async ( ) => {
488
487
await Promise . all (
489
- movieList . map ( ( movie ) => {
490
- return payload . create ( {
488
+ movieList . map ( async ( movie ) => {
489
+ return await payload . create ( {
491
490
collection : 'movies' ,
492
491
data : {
493
492
name : movie ,
@@ -528,8 +527,8 @@ describe('Relationships', () => {
528
527
it ( 'should allow clearing hasMany relationships' , async ( ) => {
529
528
const fiveMovies = await payload . find ( {
530
529
collection : 'movies' ,
531
- limit : 5 ,
532
530
depth : 0 ,
531
+ limit : 5 ,
533
532
} )
534
533
535
534
const movieIDs = fiveMovies . docs . map ( ( doc ) => doc . id )
@@ -545,8 +544,8 @@ describe('Relationships', () => {
545
544
expect ( stanley . movies ) . toHaveLength ( 5 )
546
545
547
546
const stanleyNeverMadeMovies = await payload . update ( {
548
- collection : 'directors' ,
549
547
id : stanley . id ,
548
+ collection : 'directors' ,
550
549
data : {
551
550
movies : null ,
552
551
} ,
@@ -621,18 +620,18 @@ describe('Relationships', () => {
621
620
const req = { } as PayloadRequest
622
621
req . transactionID = await payload . db . beginTransaction ?.( )
623
622
const related = await payload . create ( {
624
- req,
625
623
collection : relationSlug ,
626
624
data : {
627
625
name : 'parent' ,
628
626
} ,
627
+ req,
629
628
} )
630
629
const withRelation = await payload . create ( {
631
- req,
632
630
collection : slug ,
633
631
data : {
634
632
filteredRelation : related . id ,
635
633
} ,
634
+ req,
636
635
} )
637
636
638
637
if ( req . transactionID ) {
@@ -656,8 +655,8 @@ describe('Relationships', () => {
656
655
collection : 'polymorphic-relationships' ,
657
656
data : {
658
657
polymorphic : {
659
- value : movie . id ,
660
658
relationTo : 'movies' ,
659
+ value : movie . id ,
661
660
} ,
662
661
} ,
663
662
} )
@@ -709,9 +708,8 @@ async function createPost(overrides?: Partial<Post>) {
709
708
}
710
709
711
710
async function clearDocs ( ) : Promise < void > {
712
- const allDocs = await payload . find ( { collection : slug , limit : 100 } )
713
- const ids = allDocs . docs . map ( ( doc ) => doc . id )
714
- await mapAsync ( ids , async ( id ) => {
715
- await payload . delete ( { collection : slug , id } )
711
+ await payload . delete ( {
712
+ collection : slug ,
713
+ where : { id : { exists : true } } ,
716
714
} )
717
715
}
0 commit comments