Skip to content
This repository has been archived by the owner on Mar 20, 2023. It is now read-only.

Commit

Permalink
Include test illustrating form multi-part upload
Browse files Browse the repository at this point in the history
  • Loading branch information
leebyron committed Aug 11, 2015
1 parent bf9286d commit 5cd3f8b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"mocha": "--require resources/mocha-bootload src/**/__tests__/**/*.js"
},
"scripts": {
"prepublish": "npm test && npm run build",
"prepublish": ". ./resources/prepublish.sh",
"test": "npm run lint && npm run check && npm run testonly",
"testonly": "mocha $npm_package_options_mocha",
"lint": "eslint src",
Expand All @@ -43,8 +43,7 @@
"watch": "babel --optional runtime resources/watch.js | node",
"cover": "babel-node node_modules/.bin/isparta cover --root src --report html node_modules/.bin/_mocha -- $npm_package_options_mocha",
"cover:lcov": "babel-node node_modules/.bin/isparta cover --root src --report lcovonly node_modules/.bin/_mocha -- $npm_package_options_mocha",
"preversion": "npm test",
"prepublish": ". ./resources/prepublish.sh"
"preversion": "npm test"
},
"dependencies": {
"content-type": "~1.0.1",
Expand All @@ -68,6 +67,7 @@
"graphql": "~0.2.2",
"isparta": "3.0.3",
"mocha": "2.2.5",
"multer": "^1.0.3",
"sane": "1.1.3",
"supertest": "1.0.1",
"supertest-as-promised": "2.0.2"
Expand Down
45 changes: 45 additions & 0 deletions src/__tests__/http-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { expect } from 'chai';
import { describe, it } from 'mocha';
import { stringify } from 'querystring';
import zlib from 'zlib';
import multer from 'multer';
import request from 'supertest-as-promised';
import express4 from 'express'; // modern
import express3 from 'express3'; // old but commonly still used
Expand Down Expand Up @@ -96,6 +97,23 @@ describe('test harness', () => {
expect(caught && caught.message).to.equal('Expected to catch error.');
});

it('resolves callback promises', async () => {
var resolveValue = {};
var result = await promiseTo(cb => cb(null, resolveValue));
expect(result).to.equal(resolveValue);
});

it('rejects callback promises with errors', async () => {
var rejectError = new Error();
var caught;
try {
await promiseTo(cb => cb(rejectError));
} catch (error) {
caught = error;
}
expect(caught).to.equal(rejectError);
});

});

[[ express4, 'modern' ], [ express3, 'old' ]].forEach(([ express, version ]) => {
Expand Down Expand Up @@ -440,6 +458,33 @@ describe('test harness', () => {
});
});

it('allows for pre-parsed POST bodies', async () => {
var app = express();

// Multer provides multipart form data parsing.
var storage = multer.memoryStorage();
app.use(urlString(), multer({ storage }).single('file'));

app.use(urlString(), graphqlHTTP(req => {
expect(req.file.originalname).to.equal('http-test.js');
return {
schema: TestSchema,
rootObject: { request: req }
};
}));

var response = await request(app)
.post(urlString())
.field('query', '{ test(who: "World") }')
.attach('file', __filename);

expect(JSON.parse(response.text)).to.deep.equal({
data: {
test: 'Hello World'
}
});
});

});

describe('Pretty printing', () => {
Expand Down

0 comments on commit 5cd3f8b

Please sign in to comment.