Repository navigation
Conversation
File.delete put responseType and validateStatus into the options it passed to ServiceObject.delete, which spreads every option into queryParameters. Both ended up in the DELETE URL, including the source of the validateStatus function. The transport sets its own validateStatus, so neither option had any effect; pass the caller's options through instead. Fixes googleapis#9874
There was a problem hiding this comment.
Code Review
This pull request simplifies the delete method in File by directly passing the spread options to super.delete and removing local request options, and adds a unit test to verify transport options are not sent as query parameters. The review feedback points out that directly overwriting STORAGE.storageTransport.makeRequest in the test can cause test pollution, and suggests using sandbox.stub(object, 'method') instead for proper cleanup.
| STORAGE.storageTransport.makeRequest = sandbox | ||
| .stub() | ||
| .callsFake((reqOpts, callback) => { |
There was a problem hiding this comment.
Directly overwriting STORAGE.storageTransport.makeRequest with a stub can lead to test pollution because sandbox.restore() will not automatically restore the original method. Instead, use sandbox.stub(object, 'method') to ensure proper cleanup after the test runs.
| STORAGE.storageTransport.makeRequest = sandbox | |
| .stub() | |
| .callsFake((reqOpts, callback) => { | |
| sandbox | |
| .stub(STORAGE.storageTransport, 'makeRequest') | |
| .callsFake((reqOpts, callback) => { |
References
- Use
makeRequestrather thanrequestwhen invoking HTTP requests onStorageTransportinstances.
Fixes #9874.
File.deleteaddedresponseTypeandvalidateStatusto the options it passed toServiceObject.delete, which spreads all options intoqueryParameters. So every delete URL carried?responseType=text&validateStatus=<function source>.Neither option did anything as a transport option either:
StorageTransport.makeRequestsets its ownvalidateStatus, and a 404 still reachesFile.deletethrough theignoreNotFoundpath inServiceObject.delete. So this just passes the caller's options through.Added a test in
test/file.tsthat checks the query parameters; it fails before the change. The storage unit tests pass (1105).