Skip to content

Commit 0498937

Browse files
committed
fix(ApiDataFactory): Ensure uppercase DELETE method and add better logging
Changes: 1. Convert HTTP method to uppercase (DELETE not 'delete') for strict servers 2. Add detailed logging for delete operations (request + response) 3. Add error handling and logging for failed deletions 4. Check index exists before splicing from created array 5. Make afterEach async and add 200ms delay for Docker file sync The lowercase 'delete' method came from using the config object key directly. Some servers/proxies may reject lowercase HTTP methods. Added comprehensive logging to help diagnose deletion issues in CI: - Logs DELETE request details before sending - Logs successful deletion with status code - Logs and re-throws deletion errors The additional 200ms delay in afterEach (on top of the 100ms in _after) gives Docker environments extra time for file system synchronization.
1 parent fa36608 commit 0498937

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

lib/helper/ApiDataFactory.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ Current file error: ${err.message}`)
401401
const url = this.factories[factory].delete[method].replace('{id}', id)
402402

403403
request = {
404-
method,
404+
method: method.toUpperCase(), // Ensure HTTP method is uppercase
405405
url,
406406
}
407407
}
@@ -412,10 +412,18 @@ Current file error: ${err.message}`)
412412
return this.debugSection('Please configure the delete request in your ApiDataFactory helper', "delete: () => ({ method: 'DELETE', url: '/api/users' })")
413413
}
414414

415-
return this.restHelper._executeRequest(request).then(() => {
415+
this.debugSection('Deleting', `${request.method} ${request.baseURL}${request.url} (ID: ${id})`)
416+
417+
return this.restHelper._executeRequest(request).then((resp) => {
416418
const idx = this.created[factory].indexOf(id)
417-
this.debugSection('Deleted Id', `Id: ${id}`)
418-
this.created[factory].splice(idx, 1)
419+
this.debugSection('Deleted Successfully', `${factory} ID: ${id}, Status: ${resp.status || 'OK'}`)
420+
if (idx !== -1) {
421+
this.created[factory].splice(idx, 1)
422+
}
423+
return resp
424+
}).catch(err => {
425+
this.debugSection('Delete Failed', `${factory} ID: ${id}, Error: ${err.message}`)
426+
throw err
419427
})
420428
}
421429
}

test/rest/ApiDataFactory_test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ describe('ApiDataFactory', function () {
5252
setTimeout(done, 5000)
5353
})
5454

55-
afterEach(() => I._after())
55+
afterEach(async () => {
56+
await I._after()
57+
// Add extra delay to ensure cleanup propagates in Docker environments
58+
await new Promise(resolve => setTimeout(resolve, 200))
59+
})
5660

5761
describe('create and cleanup records', function () {
5862
this.retries(2)

0 commit comments

Comments
 (0)