Skip to content

Commit

Permalink
Add failing test for file upload (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
HriBB authored and helfer committed Aug 8, 2016
1 parent cc15ebf commit 5484fad
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/integrations/integrations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ const QueryType = new GraphQLObjectType({
},
});

const UploadedFileType = new GraphQLObjectType({
name: 'UploadedFile',
fields: {
filename: { type: GraphQLString },
mime: { type: GraphQLString },
},
});

const MutationType = new GraphQLObjectType({
name: 'MutationType',
fields: {
Expand All @@ -65,6 +73,16 @@ const MutationType = new GraphQLObjectType({
return `not really a mutation, but who cares: ${echo}`;
},
},
testUpload: {
type: UploadedFileType,
args: { echo: { type: GraphQLString } },
resolve(root) {
return {
filename: root.file.filename,
mime: root.file.mime,
};
},
},
},
});

Expand Down Expand Up @@ -300,6 +318,24 @@ export default (createApp: CreateAppFunc, destroyApp?: DestroyAppFunc) => {
});
});

it('can handle a file upload request', () => {
app = createApp();
const expected = {
testUpload: {
filename: 'integrations.test.js',
mime: 'application/javascript',
},
};
const req = request(app)
.post('/graphql')
.field('query', 'mutation test { testUpload { filename mime } }')
.attach('file', __filename);
return req.then((res) => {
expect(res.status).to.equal(200);
return expect(res.body.data).to.deep.equal(expected);
});
});

it('applies the formatResponse function', () => {
app = createApp({apolloOptions: {
schema: Schema,
Expand Down

0 comments on commit 5484fad

Please sign in to comment.