Skip to content

Commit

Permalink
fix: fix encoding and cover with test
Browse files Browse the repository at this point in the history
  • Loading branch information
znarf committed Jan 4, 2019
1 parent c237133 commit 55b672e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion server/controllers/images.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ export default function uploadImage(req, res, next) {
});
});

put.end(file.buffer.toString());
put.end(file.buffer);
}
23 changes: 18 additions & 5 deletions test/images.routes.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import app from '../server/index';
import { expect } from 'chai';
import fs from 'fs';
import path from 'path';

import request from 'supertest';
import * as utils from '../test/utils';
import fetch from 'node-fetch';
import { expect } from 'chai';

import app from '../server/index';
import models from '../server/models';
import * as utils from '../test/utils';

const application = utils.data('application');
const userData = utils.data('user1');
Expand All @@ -19,15 +24,23 @@ describe('images.routes.test.js', () => {
beforeEach(() => models.User.create(userData).tap(u => (user = u)));

it('should upload an image to S3', done => {
const originalImage = fs.readFileSync(path.join(__dirname, 'mocks/images/camera.png'), {
encoding: 'utf8',
});
request(app)
.post(`/images/?api_key=${application.api_key}`)
.attach('file', 'test/mocks/images/camera.png')
.set('Authorization', `Bearer ${user.jwt()}`)
.expect(200)
.end((err, res) => {
.then(res => {
expect(res.body.url).to.contain('.png');
return fetch(res.body.url).then(res => res.text());
})
.then(image => {
expect(image).to.equal(originalImage);
done();
});
})
.catch(done);
});

it('should throw an error if no file field is sent', done => {
Expand Down

0 comments on commit 55b672e

Please sign in to comment.