Skip to content

Commit

Permalink
Add (currently) failing test to show multerOpts/fileUploader not bein…
Browse files Browse the repository at this point in the history
…g properly passed to multer
  • Loading branch information
JacobLey committed Jan 16, 2020
1 parent c1ddb30 commit 64b0145
Showing 1 changed file with 34 additions and 18 deletions.
52 changes: 34 additions & 18 deletions test/multipart.spec.ts
Expand Up @@ -7,24 +7,39 @@ import * as packageJson from '../package.json';

describe(packageJson.name, () => {
let app = null;
const fileNames = [];
before(async () => {
const apiSpec = path.join('test', 'resources', 'multipart.yaml');
app = await createApp({ apiSpec }, 3003, app =>
app.use(
`${app.basePath}`,
express
.Router()
.post(`/sample_2`, (req, res) => {
const files = req.files;
res.status(200).json({
files,
metadata: req.body.metadata,
});
})
.post(`/sample_1`, (req, res) => res.json(req.body)),
),
app = await createApp(
{
apiSpec,
fileUploader: {
fileFilter: (req, file, cb) => {
fileNames.push(file.originalname);
cb(null, true);
},
},
},
3003,
app =>
app.use(
`${app.basePath}`,
express
.Router()
.post(`/sample_2`, (req, res) => {
const files = req.files;
res.status(200).json({
files,
metadata: req.body.metadata,
});
})
.post(`/sample_1`, (req, res) => res.json(req.body)),
),
);
});
beforeEach(() => {
fileNames.length = 0;
});
after(() => {
(<any>app).server.close();
});
Expand Down Expand Up @@ -52,8 +67,8 @@ describe(packageJson.name, () => {
.attach('file', 'package.json')
.expect(400));

it('should validate multipart file and metadata', async () =>
request(app)
it('should validate multipart file and metadata', async () => {
await request(app)
.post(`${app.basePath}/sample_2`)
.set('Content-Type', 'multipart/form-data')
.set('Accept', 'application/json')
Expand All @@ -69,8 +84,9 @@ describe(packageJson.name, () => {
.to.have.property('fieldname')
.to.equal('file');
expect(b.metadata).to.equal('some-metadata');
}));

});
expect(fileNames).to.deep.equal(['package.json']);
});
it('should throw 405 get method not allowed', async () =>
request(app)
.get(`${app.basePath}/sample_2`)
Expand Down

0 comments on commit 64b0145

Please sign in to comment.