Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: upload categories #334

Merged
merged 4 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/actions/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const {
FILES_UPLOAD_TYPE_FIELD,
STATUS_PENDING,
UPLOAD_DATA,
FILES_CATEGORIES_FIELD,
} = require('../constant');
const {
assertNotReferenced: makeAssertNotReferenced,
Expand Down Expand Up @@ -258,6 +259,10 @@ async function initFileUpload({ params, headers: { headers } }) {
fileData[FILES_DIRECT_ONLY_FIELD] = 1;
}

if (fileData[FILES_CATEGORIES_FIELD]) {
fileData[FILES_CATEGORIES_FIELD] = fileData[FILES_CATEGORIES_FIELD].join(', ');
}

const pipeline = redis.pipeline();
const uploadKey = `${FILES_DATA}:${uploadId}`;

Expand Down
21 changes: 20 additions & 1 deletion test/suites/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('upload suite', function suite() {
// data
let bucketName;
const route = 'files.upload';
const { STATUS_PENDING, STATUS_PROCESSED, FILES_PACKED_FIELD } = require('../../src/constant');
const { STATUS_PENDING, STATUS_PROCESSED, FILES_PACKED_FIELD, FILES_CATEGORIES_FIELD } = require('../../src/constant');

// setup functions
before('start service', async function startAll() {
Expand Down Expand Up @@ -242,6 +242,25 @@ describe('upload suite', function suite() {
});
});

describe('categories', function suiteCategories() {
it('should upload with categories', async function test () {
const { message } = simpleData;
const categories = ['_s1_c1', '_s1_c2'];
const rsp = await this.send({
...message,
meta: {
...meta,
...message.meta,
[FILES_CATEGORIES_FIELD]: categories,
},
});
assert.deepEqual(rsp[FILES_CATEGORIES_FIELD], categories);

const infoResp = await getInfo.call(this, { filename: rsp.uploadId, username: message.username });
assert.deepEqual(infoResp.file[FILES_CATEGORIES_FIELD], categories);
});
});

describe('signed url', function signedURLSuite() {
let response;

Expand Down