Skip to content

Commit

Permalink
Merge pull request #88 from Inist-CNRS/fix_import_count
Browse files Browse the repository at this point in the history
[RFR] properly count dataset at the end of the upload
  • Loading branch information
djhi authored Feb 21, 2017
2 parents 3d4d5fd + 232df39 commit dfed0a5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/api/controller/api/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export async function uploadMiddleware(ctx) {
await ctx.dataset.insertBatch(documents);
ctx.status = 200;
ctx.body = {
totalLines: documents.length,
totalLines: await ctx.dataset.count(),
};
} catch (error) {
ctx.status = 500;
Expand Down
6 changes: 3 additions & 3 deletions src/api/controller/api/upload.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe('upload', () => {
},
dataset: {
remove: () => Promise.resolve(),
count: () => Promise.resolve('dataset count'),
},
getParser: () => {
throw new Error('Parsing error');
Expand All @@ -27,7 +28,6 @@ describe('upload', () => {
it('should call all ctx method in turn and have body set to parser result length', async () => {
const myParser = () => Promise.resolve({
name: 'myParser result',
length: 'myParser result length',
});
const myStream = {
put: buffer => expect(buffer).toBe('buffer'),
Expand All @@ -44,9 +44,9 @@ describe('upload', () => {
insertBatch: (documents) => {
expect(documents).toEqual({
name: 'myParser result',
length: 'myParser result length',
});
},
count: () => Promise.resolve('dataset count'),
},
getParser: (type) => {
expect(type).toBe('text/csv');
Expand All @@ -63,7 +63,7 @@ describe('upload', () => {
await uploadMiddleware(ctx);

expect(ctx.body).toEqual({
totalLines: 'myParser result length',
totalLines: 'dataset count',
});
});
});

0 comments on commit dfed0a5

Please sign in to comment.