MCPcopy Index your code
hub / github.com/codeceptjs/CodeceptJS / _requestDelete

Method _requestDelete

lib/helper/ApiDataFactory.js:397–436  ·  view source on GitHub ↗

* Executes request to delete a record in API * Can be replaced from a custom helper. * * @param {*} factory * @param {*} id

(factory, id)

Source from the content-addressed store, hash-verified

395 * @param {*} id
396 */
397 _requestDelete(factory, id) {
398 if (!this.factories[factory].delete) return
399 let request = createRequestFromFunction(this.factories[factory].delete, id)
400
401 if (!request) {
402 const method = Object.keys(this.factories[factory].delete)[0]
403
404 const url = this.factories[factory].delete[method].replace('{id}', id)
405
406 request = {
407 method: method.toUpperCase(), // Ensure HTTP method is uppercase
408 url,
409 }
410 }
411
412 // Ensure method is uppercase (some servers require uppercase HTTP methods)
413 if (request.method) {
414 request.method = request.method.toUpperCase()
415 }
416
417 request.baseURL = this.config.endpoint
418
419 if (request.url.match(/^undefined/)) {
420 return this.debugSection('Please configure the delete request in your ApiDataFactory helper', "delete: () => ({ method: 'DELETE', url: '/api/users' })")
421 }
422
423 this.debugSection('Deleting', `${request.method} ${request.baseURL}${request.url} (ID: ${id})`)
424
425 return this.restHelper._executeRequest(request).then((resp) => {
426 const idx = this.created[factory].indexOf(id)
427 this.debugSection('Deleted Successfully', `${factory} ID: ${id}, Status: ${resp.status || 'OK'}`)
428 if (idx !== -1) {
429 this.created[factory].splice(idx, 1)
430 }
431 return resp
432 }).catch(err => {
433 this.debugSection('Delete Failed', `${factory} ID: ${id}, Error: ${err.message}`)
434 throw err
435 })
436 }
437}
438
439export { ApiDataFactory as default }

Callers 1

_afterMethod · 0.95

Calls 2

_executeRequestMethod · 0.80

Tested by

no test coverage detected