|
|
|
@ -29,6 +29,7 @@ describe('Topic thumbs', () => {
|
|
|
|
|
let fooCSRF;
|
|
|
|
|
let fooUid;
|
|
|
|
|
const thumbPaths = [`${nconf.get('upload_path')}/files/test.png`, `${nconf.get('upload_path')}/files/test2.png`, 'https://example.org'];
|
|
|
|
|
const relativeThumbPaths = thumbPaths.map(path => path.replace(nconf.get('upload_path'), ''));
|
|
|
|
|
const uuid = utils.generateUUID();
|
|
|
|
|
|
|
|
|
|
function createFiles() {
|
|
|
|
@ -112,7 +113,7 @@ describe('Topic thumbs', () => {
|
|
|
|
|
path: thumbPaths[0],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const exists = await db.isSortedSetMember(`topic:2:thumbs`, thumbPaths[0]);
|
|
|
|
|
const exists = await db.isSortedSetMember(`topic:2:thumbs`, relativeThumbPaths[0]);
|
|
|
|
|
assert(exists);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -122,7 +123,7 @@ describe('Topic thumbs', () => {
|
|
|
|
|
path: thumbPaths[1],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const exists = await db.isSortedSetMember(`draft:${uuid}:thumbs`, thumbPaths[1]);
|
|
|
|
|
const exists = await db.isSortedSetMember(`draft:${uuid}:thumbs`, relativeThumbPaths[1]);
|
|
|
|
|
assert(exists);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -132,7 +133,7 @@ describe('Topic thumbs', () => {
|
|
|
|
|
path: thumbPaths[2],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const exists = await db.isSortedSetMember(`topic:2:thumbs`, thumbPaths[2]);
|
|
|
|
|
const exists = await db.isSortedSetMember(`topic:2:thumbs`, relativeThumbPaths[2]);
|
|
|
|
|
assert(exists);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
@ -147,7 +148,7 @@ describe('Topic thumbs', () => {
|
|
|
|
|
{
|
|
|
|
|
id: 2,
|
|
|
|
|
name: 'test.png',
|
|
|
|
|
url: `${nconf.get('upload_url')}${thumbPaths[0]}`,
|
|
|
|
|
url: `${nconf.get('upload_url')}${relativeThumbPaths[0]}`,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 2,
|
|
|
|
@ -157,7 +158,7 @@ describe('Topic thumbs', () => {
|
|
|
|
|
{
|
|
|
|
|
id: 2,
|
|
|
|
|
name: 'test2.png',
|
|
|
|
|
url: `${nconf.get('upload_url')}${thumbPaths[1]}`,
|
|
|
|
|
url: `${nconf.get('upload_url')}${relativeThumbPaths[1]}`,
|
|
|
|
|
},
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
@ -169,10 +170,10 @@ describe('Topic thumbs', () => {
|
|
|
|
|
id: 1,
|
|
|
|
|
path: thumbPaths[0],
|
|
|
|
|
});
|
|
|
|
|
await topics.thumbs.delete(1, thumbPaths[0]);
|
|
|
|
|
await topics.thumbs.delete(1, relativeThumbPaths[0]);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(await db.isSortedSetMember('topic:1:thumbs', thumbPaths[0]), false);
|
|
|
|
|
assert.strictEqual(await file.exists(`${nconf.get('upload_path')}${thumbPaths[0]}`), false);
|
|
|
|
|
assert.strictEqual(await db.isSortedSetMember('topic:1:thumbs', relativeThumbPaths[0]), false);
|
|
|
|
|
assert.strictEqual(await file.exists(thumbPaths[0]), false);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should also work with UUIDs', async () => {
|
|
|
|
@ -180,10 +181,10 @@ describe('Topic thumbs', () => {
|
|
|
|
|
id: uuid,
|
|
|
|
|
path: thumbPaths[1],
|
|
|
|
|
});
|
|
|
|
|
await topics.thumbs.delete(uuid, thumbPaths[1]);
|
|
|
|
|
await topics.thumbs.delete(uuid, relativeThumbPaths[1]);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(await db.isSortedSetMember(`draft:${uuid}:thumbs`, thumbPaths[1]), false);
|
|
|
|
|
assert.strictEqual(await file.exists(`${nconf.get('upload_path')}${thumbPaths[1]}`), false);
|
|
|
|
|
assert.strictEqual(await db.isSortedSetMember(`draft:${uuid}:thumbs`, relativeThumbPaths[1]), false);
|
|
|
|
|
assert.strictEqual(await file.exists(thumbPaths[1]), false);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should also work with URLs', async () => {
|
|
|
|
@ -191,15 +192,15 @@ describe('Topic thumbs', () => {
|
|
|
|
|
id: uuid,
|
|
|
|
|
path: thumbPaths[2],
|
|
|
|
|
});
|
|
|
|
|
await topics.thumbs.delete(uuid, thumbPaths[2]);
|
|
|
|
|
await topics.thumbs.delete(uuid, relativeThumbPaths[2]);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(await db.isSortedSetMember(`draft:${uuid}:thumbs`, thumbPaths[2]), false);
|
|
|
|
|
assert.strictEqual(await db.isSortedSetMember(`draft:${uuid}:thumbs`, relativeThumbPaths[2]), false);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should not delete the file from disk if not associated with the tid', async () => {
|
|
|
|
|
createFiles();
|
|
|
|
|
await topics.thumbs.delete(uuid, thumbPaths[0]);
|
|
|
|
|
assert.strictEqual(await file.exists(`${nconf.get('upload_path')}${thumbPaths[0]}`), true);
|
|
|
|
|
assert.strictEqual(await file.exists(thumbPaths[0]), true);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|