Skip to content

Commit

Permalink
Additional testing
Browse files Browse the repository at this point in the history
  • Loading branch information
bosschaert committed Oct 16, 2024
1 parent e8b00f8 commit aed0471
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/storage/object/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ async function invalidateCollab(api, url, env) {
}

export async function deleteObject(client, daCtx, Key, env, isMove = false) {
if (!Key.endsWith('.props')) {
const fname = Key.split('/').pop();

if (fname.includes('.') && !Key.endsWith('.props')) {
await postObjectVersionWithLabel(isMove ? 'Moved' : 'Deleted', env, daCtx);
}

Expand Down
96 changes: 96 additions & 0 deletions test/storage/object/delete.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,102 @@ describe('Object delete', () => {
}
});

it('Delete dir', 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/a/b/c/d';
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, 'd', env, true);
assert.equal(204, resp.status);
assert.deepStrictEqual([], postObjVerCalled);
} finally {
globalThis.fetch = savedFetch;
}
});

it('Delete properties file', 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/a/b/c/d.props';
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, 'd.props', env, true);
assert.equal(204, resp.status);
assert.deepStrictEqual([], postObjVerCalled);
} finally {
globalThis.fetch = savedFetch;
}
});

it('Move a non-doc resource', async () => {
const client = {};
const daCtx = {};
Expand Down

0 comments on commit aed0471

Please sign in to comment.