-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c2c60f2
commit 4726fde
Showing
6 changed files
with
142 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/* | ||
* Copyright 2024 Adobe. All rights reserved. | ||
* This file is licensed to you under the Apache License, Version 2.0 (the 'License'); | ||
* you may not use this file except in compliance with the License. You may obtain a copy | ||
* of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under | ||
* the License is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
* OF ANY KIND, either express or implied. See the License for the specific language | ||
* governing permissions and limitations under the License. | ||
*/ | ||
import assert from 'node:assert'; | ||
import esmock from 'esmock'; | ||
|
||
describe('Object delete', () => { | ||
it('Delete a file', async () => { | ||
const collabCalled = [] | ||
const dacollab = { fetch: (u) => collabCalled.push(u) }; | ||
|
||
const client = {}; | ||
const env = { dacollab }; | ||
const daCtx = { | ||
origin: 'https://admin.da.live', | ||
org: 'testorg', | ||
}; | ||
|
||
const postObjVerCalled = []; | ||
const mockPostObjectVersion = async (l, e, c) => { | ||
if (l === 'Deleted' && e === env && c === daCtx) { | ||
postObjVerCalled.push('postObjectVersionWithLabel'); | ||
return {status: 201}; | ||
} | ||
}; | ||
|
||
const deleteURL = 'https://localhost:9876/foo/bar.html'; | ||
const mockSignedUrl = async (cl, cm) => { | ||
if (cl === client | ||
&& cm.constructor.toString().includes('DeleteObjectCommand')) { | ||
return deleteURL; | ||
} | ||
}; | ||
|
||
const { deleteObject } = await esmock( | ||
'../../../src/storage/object/delete.js', { | ||
'../../../src/storage/version/put.js': { | ||
postObjectVersionWithLabel: mockPostObjectVersion, | ||
}, | ||
'@aws-sdk/s3-request-presigner': { | ||
getSignedUrl: mockSignedUrl, | ||
} | ||
} | ||
); | ||
|
||
const savedFetch = globalThis.fetch; | ||
try { | ||
globalThis.fetch = async (url, opts) => { | ||
assert.equal(deleteURL, url); | ||
assert.equal('DELETE', opts.method); | ||
return {status: 204}; | ||
}; | ||
|
||
const resp = await deleteObject(client, daCtx, 'foo/bar.html', env); | ||
assert.equal(204, resp.status); | ||
assert.deepStrictEqual(['postObjectVersionWithLabel'], postObjVerCalled); | ||
assert.deepStrictEqual( | ||
['https://localhost/api/v1/deleteadmin?doc=https://admin.da.live/source/testorg/foo/bar.html'], | ||
collabCalled | ||
); | ||
} finally { | ||
globalThis.fetch = savedFetch; | ||
} | ||
}); | ||
|
||
it('Move a non-doc resource', async () => { | ||
const client = {}; | ||
const daCtx = {}; | ||
const env = {}; | ||
|
||
const postObjVerCalled = []; | ||
const mockPostObjectVersion = async (l, e, c) => { | ||
if (l === 'Moved' && e === env && c === daCtx) { | ||
postObjVerCalled.push('postObjectVersionWithLabel'); | ||
return {status: 201}; | ||
} | ||
}; | ||
|
||
const deleteURL = 'https://localhost:9876/aha.png'; | ||
const mockSignedUrl = async (cl, cm) => { | ||
if (cl === client | ||
&& cm.constructor.toString().includes('DeleteObjectCommand')) { | ||
return deleteURL; | ||
} | ||
}; | ||
|
||
const { deleteObject } = await esmock( | ||
'../../../src/storage/object/delete.js', { | ||
'../../../src/storage/version/put.js': { | ||
postObjectVersionWithLabel: mockPostObjectVersion, | ||
}, | ||
'@aws-sdk/s3-request-presigner': { | ||
getSignedUrl: mockSignedUrl, | ||
} | ||
} | ||
); | ||
|
||
const savedFetch = globalThis.fetch; | ||
try { | ||
globalThis.fetch = async (url, opts) => { | ||
assert.equal(deleteURL, url); | ||
assert.equal('DELETE', opts.method); | ||
return {status: 204}; | ||
}; | ||
|
||
const resp = await deleteObject(client, daCtx, 'aha.png', env, true); | ||
assert.equal(204, resp.status); | ||
assert.deepStrictEqual(['postObjectVersionWithLabel'], postObjVerCalled); | ||
} finally { | ||
globalThis.fetch = savedFetch; | ||
} | ||
}); | ||
}); |