@@ -3,7 +3,7 @@ import { AxiosInstance } from 'axios';
3
3
import * as api from '../../api' ;
4
4
import { getProjectApi } from '../project' ;
5
5
6
- import { Query } from '../../types' ;
6
+ import { DeletedEntities , Query } from '../../types' ;
7
7
8
8
describe ( 'Project Entities' , ( ) => {
9
9
const apiEntities = [
@@ -165,6 +165,40 @@ describe('Project Entities', () => {
165
165
expect ( apiClient . put ) . toHaveBeenCalledWith (
166
166
'/projects/project1/entities/entity1' , expectedEntity ) ;
167
167
} ) ;
168
- } ) ;
168
+ } ) ;
169
+ describe ( 'delete' , ( ) => {
170
+ async function callMockDelete ( entityId : string ) : Promise < dataHelpers . WrappedEntity > {
171
+ apiClient = api . getApiClient ( 'http://baseurl' , 'somekey' ) ;
172
+ jest . spyOn ( apiClient , 'delete' ) . mockReturnValue ( Promise . resolve ( { data :
173
+ { ...apiEntities [ 0 ] } } ) ) ;
174
+ jest . spyOn ( dataHelpers , 'wrapEntity' ) ;
175
+ const project = getProjectApi ( 'project1' , apiClient ) ;
176
+ const ent = await project . entities . delete ( entityId ) ;
177
+ return ent ;
178
+ }
179
+
180
+ async function callMockDeleteMany ( entityIds : string [ ] ) : Promise < DeletedEntities > {
181
+ apiClient = api . getApiClient ( 'http://baseurl' , 'somekey' ) ;
182
+ jest . spyOn ( apiClient , 'delete' ) . mockReturnValue ( Promise . resolve ( { data :
183
+ { deleted : entityIds . length } } ) ) ;
184
+ jest . spyOn ( dataHelpers , 'wrapEntity' ) ;
185
+ const project = getProjectApi ( 'project1' , apiClient ) ;
186
+ const ent = await project . entities . deleteMany ( entityIds ) ;
187
+ return ent ;
188
+ }
189
+
190
+ it ( 'should call DELETE /projects/:pid/entities/:eid' , async ( ) => {
191
+ const entityId = 'entity1' ;
192
+ await callMockDelete ( entityId ) ;
193
+ expect ( apiClient . delete ) . toHaveBeenCalledWith ( `/projects/project1/entities/${ entityId } ` ) ;
194
+ } ) ;
195
+ it ( 'should call DELETE /projects/:pid/entities with a list of entity ids' , async ( ) => {
196
+ const entityIds = [ 'entity1' , 'entity2' ] ;
197
+
198
+ await callMockDeleteMany ( entityIds ) ;
199
+ expect ( apiClient . delete ) . toHaveBeenCalledWith ( `/projects/project1/entities` ,
200
+ { data : { entities : entityIds } } ) ;
201
+ } ) ;
202
+ } ) ;
169
203
} ) ;
170
204
} ) ;
0 commit comments