-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.ts
30 lines (25 loc) · 902 Bytes
/
test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import * as test from 'tape';
import * as sinon from 'sinon';
import * as request from 'supertest';
import app from './src/index';
import * as aws from './src/services/aws';
const testSvg = '<svg viewBox="0 0 10 10"><circle cx="5" cy="5" r="2"/></svg>';
test('svgthumb-api POST /', (t: test.Test): void => {
t.plan(3);
const consoleStub = sinon.stub(console, 'log');
const awsUploadStub = sinon.stub(aws, 'upload').returns(Promise.resolve('S3 URL'));
const server = app.listen();
request(server)
.post('/')
.set('Content-Type', 'text/plain')
.send(testSvg)
.expect('X-Powered-By', /svgthumb-api/)
.expect('S3 URL')
.end((error: Error): void => {
sinon.restore();
server.close();
t.notOk(error, 'does not return an error');
t.ok(consoleStub.calledOnce, 'logs request');
t.ok(awsUploadStub.calledOnce, 'calls AWS upload');
});
});