|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var fixtures = require('../../fixtures'); |
| 4 | +var HTTPSnippet = require('../../../src'); |
| 5 | +var should = require('should'); |
| 6 | + |
| 7 | +describe('OCaml', function () { |
| 8 | + it('should convert full request to an OCaml snippet', function (done) { |
| 9 | + var result = new HTTPSnippet(fixtures.full).convert('ocaml', 'cohttp', { |
| 10 | + indent: '\t' |
| 11 | + }); |
| 12 | + |
| 13 | + result.replace(/\n/g, '').should.eql('open Cohttp_lwt_unixopen Lwtlet uri = Uri.of_string "http://httpconsole.com/debug?baz=abc&foo=bar&foo=baz" inlet headers = Header.init ()\t|> fun h -> Header.add h "Accept" "text/plain"\t|> fun h -> Header.add h "Content-Type" "application/json"\t|> fun h -> Header.add h "X-Pretty-Print" "2"\t|> fun h -> Header.add h "Cookie" "foo=bar; bar=baz"inlet body = "{\\"foo\\": \\"bar\\"}" inClient.call ~headers ~body (Code.method_of_string "POST") uri>>= fun (res, body_stream) ->\t(* Do stuff with the result *)'); |
| 14 | + |
| 15 | + done(); |
| 16 | + }); |
| 17 | + |
| 18 | + it('should convert query request to an OCaml snippet', function (done) { |
| 19 | + var result = new HTTPSnippet(fixtures.query).convert('ocaml', 'cohttp', { |
| 20 | + indent: '\t' |
| 21 | + }); |
| 22 | + |
| 23 | + result.replace(/\n/g, '').should.eql('open Cohttp_lwt_unixopen Lwtlet uri = Uri.of_string "http://httpconsole.com/debug?key=value&baz=abc&foo=bar&foo=baz" inClient.call (Code.method_of_string "POST") uri>>= fun (res, body_stream) ->\t(* Do stuff with the result *)'); |
| 24 | + |
| 25 | + done(); |
| 26 | + }); |
| 27 | + |
| 28 | + it('should convert simple request to an OCaml snippet', function (done) { |
| 29 | + var result = new HTTPSnippet(fixtures.simple).convert('ocaml', 'cohttp', { |
| 30 | + indent: '\t' |
| 31 | + }); |
| 32 | + |
| 33 | + result.replace(/\n/g, '').should.eql('open Cohttp_lwt_unixopen Lwtlet uri = Uri.of_string "http://httpconsole.com/debug?foo=bar" inlet headers = Header.init ()\t|> fun h -> Header.add h "Content-Type" "application/json"\t|> fun h -> Header.add h "Cookie" "bar=baz"inlet body = "{\\"foo\\": \\"bar\\"}" inClient.call ~headers ~body (Code.method_of_string "POST") uri>>= fun (res, body_stream) ->\t(* Do stuff with the result *)'); |
| 34 | + |
| 35 | + done(); |
| 36 | + }); |
| 37 | + |
| 38 | + it('should convert short request to an OCaml snippet', function (done) { |
| 39 | + var result = new HTTPSnippet(fixtures.short).convert('ocaml', 'cohttp', { |
| 40 | + indent: '\t' |
| 41 | + }); |
| 42 | + |
| 43 | + result.replace(/\n/g, '').should.eql('open Cohttp_lwt_unixopen Lwtlet uri = Uri.of_string "http://httpconsole.com/echo" inClient.call (Code.method_of_string "GET") uri>>= fun (res, body_stream) ->\t(* Do stuff with the result *)'); |
| 44 | + |
| 45 | + done(); |
| 46 | + }); |
| 47 | + |
| 48 | + it('should convert http1 request to an OCaml snippet', function (done) { |
| 49 | + var result = new HTTPSnippet(fixtures.http1).convert('ocaml', 'cohttp', { |
| 50 | + indent: '\t' |
| 51 | + }); |
| 52 | + |
| 53 | + result.replace(/\n/g, '').should.eql('open Cohttp_lwt_unixopen Lwtlet uri = Uri.of_string "http://httpconsole.com/debug" inClient.call (Code.method_of_string "GET") uri>>= fun (res, body_stream) ->\t(* Do stuff with the result *)'); |
| 54 | + |
| 55 | + done(); |
| 56 | + }); |
| 57 | +}); |
0 commit comments