|
| 1 | +import assert from "assert"; |
| 2 | +import request from "supertest"; |
| 3 | +import app from "../app"; |
| 4 | + |
| 5 | +describe("POST /magic", function() { |
| 6 | + it("should error helpfully if there's no `input` property in request body", (done) => { |
| 7 | + request(app) |
| 8 | + .post("/magic") |
| 9 | + .send({}) |
| 10 | + .expect(400) |
| 11 | + .expect("'input' property is required in request body", done); |
| 12 | + }); |
| 13 | + |
| 14 | + it("should return JSON when given some input, without content-type header", (done) => { |
| 15 | + request(app) |
| 16 | + .post("/magic") |
| 17 | + .send({input: "WUagwsiae6mP8gNtCCLUFpCpCB26RmBDoDD8PacdAmzAzBVjkK2QstFXaKhpC6iUS7RHqXrJtFisoRSgoJ4whjm1arm864qaNq4RcfUmLHrcsAaZc5TXCYifNdgS83gDeejGX46gaiMyuBV6EskHt1scgJ88x2tNSotQDwbGY1mmCob2ARGFvCKYNqiN9ipMq1ZU1mgkdbNuGcb76aRtYWhCGUc8g93UJudhb8htsheZnwTpgqhx83SVJSZXMXUjJT2zmpC7uXWtumqokbdSi88YtkWDAc1Toouh2oH4D4ddmNKJWUDpMwmngUmK14xwmomccPQE9hM172APnSqwxdKQ172RkcAsysnmj5gGtRmVNNh2s359wr6mS2QRP"}) |
| 18 | + .expect(200) |
| 19 | + .expect(response => { |
| 20 | + assert.ok(response); |
| 21 | + assert.ok(response.body); |
| 22 | + assert.ok(response.body.value); |
| 23 | + assert.ok(response.body.type); |
| 24 | + assert.deepEqual(response.body.type, 6); // 6 is Dish.JSON enum value |
| 25 | + }) |
| 26 | + .end((err, res) => { |
| 27 | + if (err) { |
| 28 | + return done(err); |
| 29 | + } |
| 30 | + return done(); |
| 31 | + }); |
| 32 | + }); |
| 33 | + |
| 34 | + it("should apply optional arguments provided as an object", (done) => { |
| 35 | + request(app) |
| 36 | + .post("/magic") |
| 37 | + .send({ |
| 38 | + input: "WUagwsiae6mP8gNtCCLUFpCpCB26RmBDoDD8PacdAmzAzBVjkK2QstFXaKhpC6iUS7RHqXrJtFisoRSgoJ4whjm1arm864qaNq4RcfUmLHrcsAaZc5TXCYifNdgS83gDeejGX46gaiMyuBV6EskHt1scgJ88x2tNSotQDwbGY1mmCob2ARGFvCKYNqiN9ipMq1ZU1mgkdbNuGcb76aRtYWhCGUc8g93UJudhb8htsheZnwTpgqhx83SVJSZXMXUjJT2zmpC7uXWtumqokbdSi88YtkWDAc1Toouh2oH4D4ddmNKJWUDpMwmngUmK14xwmomccPQE9hM172APnSqwxdKQ172RkcAsysnmj5gGtRmVNNh2s359wr6mS2QRP", |
| 39 | + args: { |
| 40 | + depth: 1, |
| 41 | + }, |
| 42 | + }) |
| 43 | + .expect(200) |
| 44 | + .expect(response => { |
| 45 | + assert.ok(Array.isArray(response.body.value)); |
| 46 | + assert.strictEqual(response.body.value.length, 2); // This would be longer if depth was default 3 |
| 47 | + }) |
| 48 | + .end((err, result) => { |
| 49 | + if (err) { |
| 50 | + return done(err); |
| 51 | + } |
| 52 | + done(); |
| 53 | + }); |
| 54 | + }); |
| 55 | + |
| 56 | + it("should apply optional arguments provided as an array", (done) => { |
| 57 | + request(app) |
| 58 | + .post("/magic") |
| 59 | + .send({ |
| 60 | + input: "WUagwsiae6mP8gNtCCLUFpCpCB26RmBDoDD8PacdAmzAzBVjkK2QstFXaKhpC6iUS7RHqXrJtFisoRSgoJ4whjm1arm864qaNq4RcfUmLHrcsAaZc5TXCYifNdgS83gDeejGX46gaiMyuBV6EskHt1scgJ88x2tNSotQDwbGY1mmCob2ARGFvCKYNqiN9ipMq1ZU1mgkdbNuGcb76aRtYWhCGUc8g93UJudhb8htsheZnwTpgqhx83SVJSZXMXUjJT2zmpC7uXWtumqokbdSi88YtkWDAc1Toouh2oH4D4ddmNKJWUDpMwmngUmK14xwmomccPQE9hM172APnSqwxdKQ172RkcAsysnmj5gGtRmVNNh2s359wr6mS2QRP", |
| 61 | + args: [1, true, false, ""], |
| 62 | + }) |
| 63 | + .expect(200) |
| 64 | + .expect(response => { |
| 65 | + assert.ok(Array.isArray(response.body.value)); |
| 66 | + assert.strictEqual(response.body.value.length, 24); // intensive language support true => lots of suggestions |
| 67 | + }) |
| 68 | + .end((err, result) => { |
| 69 | + if (err) { |
| 70 | + return done(err); |
| 71 | + } |
| 72 | + done(); |
| 73 | + }); |
| 74 | + }); |
| 75 | + |
| 76 | +}); |
0 commit comments