« index

Coverage for /Users/kris/q-io/spec/http-apps/cookie-spec.js : 100%

50 lines | 50 run | 0 missing | 0 partial | 8 blocks | 8 blocks run | 0 blocks missing

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

  require("../lib/jasmine-promise");
  var Q = require("q");
  var Http = require("../../http");
  var Apps = require("../../http-apps");
  
  describe("http cookies", function () {
  
      var hosts = ["localhost", "127.0.0.1"];
  
      hosts.forEach(function (host) {
          it("should work on host" + host, function () {
  
              var server = Http.Server(function (request) {
                  return {
                      status: 200,
                      headers: {
                          "set-cookie": "a=10; MaxAge=1"
                      },
                      body: [request.headers.cookie || ""]
                  };
              });
  
              var request = Apps.Normalize(Apps.CookieJar(Http.request));
  
              return server.listen(0)
              .then(function (server) {
                  var address = server.node.address();
                  return request("http://" + host + ":" + address.port)
                  .get("body")
                  .invoke("read")
                  .invoke("toString", "utf-8")
                  .then(function (content) {
                      expect(content).toEqual(""); // no cookie first time
                  })
                  .then(function () {
                      return request("http://" + host + ":" + address.port)
                      .get("body")
                      .invoke("read")
                      .invoke("toString", "utf-8")
                  })
                  .then(function (content) {
                      expect(content).toEqual("a=10"); // cookie set second time
                  })
              })
              .timeout(1000)
              .finally(server.stop)
          });
      });
  
  });
« index | cover.io