|
29 | 29 | * POSSIBILITY OF SUCH DAMAGE.
|
30 | 30 | */
|
31 | 31 | "use strict";
|
32 |
| -const util = require("util"); |
33 | 32 | const vows = require("vows");
|
34 | 33 | const assert = require("assert");
|
35 | 34 | const async = require("async");
|
36 | 35 | const tough = require("../lib/cookie");
|
37 | 36 | const Cookie = tough.Cookie;
|
38 | 37 | const CookieJar = tough.CookieJar;
|
39 |
| -const Store = tough.Store; |
40 |
| -const MemoryCookieStore = tough.MemoryCookieStore; |
41 | 38 |
|
42 | 39 | const atNow = Date.now();
|
43 | 40 |
|
|
84 | 81 | }
|
85 | 82 | }
|
86 | 83 | })
|
| 84 | + .addBatch({ |
| 85 | + "CookieJar Promises": { |
| 86 | + topic: () => new CookieJar(), |
| 87 | + setCookie: { |
| 88 | + topic(jar) { |
| 89 | + jar |
| 90 | + .setCookie("foo=bar", "http://example.com") |
| 91 | + .then(c => this.callback(null, c), this.callback); |
| 92 | + }, |
| 93 | + "resolves to a Cookie"(cookie) { |
| 94 | + assert.ok(cookie instanceof Cookie); |
| 95 | + assert.strictEqual(cookie.key, "foo"); |
| 96 | + assert.strictEqual(cookie.value, "bar"); |
| 97 | + } |
| 98 | + }, |
| 99 | + getCookies: { |
| 100 | + topic(jar) { |
| 101 | + jar |
| 102 | + .getCookies("http://example.com") |
| 103 | + .then(cookies => this.callback(null, cookies), this.callback); |
| 104 | + }, |
| 105 | + "resolves to an array of cookies"(cookies) { |
| 106 | + assert.ok(Array.isArray(cookies), "not an array"); |
| 107 | + assert.ok(cookies.length > 0, "array is empty"); |
| 108 | + for (const cookie of cookies) { |
| 109 | + assert.ok(cookie instanceof Cookie, "not instanceof Cookie"); |
| 110 | + } |
| 111 | + } |
| 112 | + }, |
| 113 | + getCookieString: { |
| 114 | + topic(jar) { |
| 115 | + jar |
| 116 | + .getCookieString("http://example.com") |
| 117 | + .then(cookies => this.callback(null, cookies), this.callback); |
| 118 | + }, |
| 119 | + "resolves to a string"(cookies) { |
| 120 | + assert.ok(typeof cookies === "string", "not a string"); |
| 121 | + } |
| 122 | + }, |
| 123 | + getSetCookieStrings: { |
| 124 | + topic(jar) { |
| 125 | + jar |
| 126 | + .getSetCookieStrings("http://example.com") |
| 127 | + .then(cookies => this.callback(null, cookies), this.callback); |
| 128 | + }, |
| 129 | + "resolves to a an array of strings"(cookies) { |
| 130 | + assert.ok(Array.isArray(cookies), "not an array"); |
| 131 | + assert.ok(cookies.length > 0, "array is empty"); |
| 132 | + for (const cookie of cookies) { |
| 133 | + assert.ok(typeof cookie === "string", "not a string"); |
| 134 | + } |
| 135 | + } |
| 136 | + }, |
| 137 | + removeAllCookies: { |
| 138 | + topic(jar) { |
| 139 | + jar.removeAllCookies().then(this.callback, this.callback); |
| 140 | + }, |
| 141 | + "resolves to undefined"(arg) { |
| 142 | + assert.ok(arg === undefined, "was not undefined"); |
| 143 | + } |
| 144 | + }, |
| 145 | + serialize: { |
| 146 | + topic(jar) { |
| 147 | + jar |
| 148 | + .serialize() |
| 149 | + .then(data => this.callback(null, data), this.callback); |
| 150 | + }, |
| 151 | + "resolves to an object"(data) { |
| 152 | + assert.ok(data instanceof Object, "not an object"); |
| 153 | + } |
| 154 | + } |
| 155 | + } |
| 156 | + }) |
87 | 157 | .addBatch({
|
88 | 158 | "expiry option": {
|
89 | 159 | topic: function() {
|
|
0 commit comments