[Pkg-javascript-commits] [node-mocks-http] 24/296: Adding cookie and clearCookie method

Thorsten Alteholz alteholz at moszumanska.debian.org
Mon Feb 8 18:13:17 UTC 2016


This is an automated email from the git hooks/post-receive script.

alteholz pushed a commit to branch master
in repository node-mocks-http.

commit aef742ad6f45b242e19cebe8ea461444a7142f6e
Author: Andrew E Gall <agall at groupon.com>
Date:   Sat Mar 2 03:18:24 2013 +0100

    Adding cookie and clearCookie method
---
 lib/mockResponse.js       |  8 ++++++++
 test/test-mockResponse.js | 17 +++++++++++++----
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/lib/mockResponse.js b/lib/mockResponse.js
index 0ed66e0..90c770b 100644
--- a/lib/mockResponse.js
+++ b/lib/mockResponse.js
@@ -45,6 +45,14 @@ exports.createResponse = function(options) {
 
         cookies: {},
 
+        cookie: function(name, value, options) {
+          this.cookies[name] = { value: value, options: options };
+        },
+
+        clearCookie: function(name) {
+          delete this.cookies[name]
+        },
+
         status: function(code) {
             this.statusCode = code;
             return this;
diff --git a/test/test-mockResponse.js b/test/test-mockResponse.js
index c46fd0d..8eef04f 100644
--- a/test/test-mockResponse.js
+++ b/test/test-mockResponse.js
@@ -176,10 +176,19 @@ exports['cookies - Cookies creation'] = function(test) {
   var response = httpMocks.createResponse();
   test.deepEqual(response.cookies, {});
   test.done();
-}
+};
+
 exports['cookies - Cookies assignment'] = function(test) {
   var response = httpMocks.createResponse();
-  response.cookies.egg = 'chicken';
-  test.deepEqual(response.cookies, {egg: 'chicken'});
+  response.cookie("egg", "chicken", { maxAge: 1000 });
+  test.deepEqual(response.cookies, {egg: {value: 'chicken', options: { maxAge: 1000 }}});
+  test.done();
+};
+
+exports['cookies - Cookie deletion'] = function(test) {
+  var response = httpMocks.createResponse();
+  response.cookie("egg", "chicken", { maxAge: 1000 });
+  response.clearCookie("egg");
+  test.deepEqual(response.cookies, {});
   test.done();
-}
+};

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-mocks-http.git



More information about the Pkg-javascript-commits mailing list