Permalink
Browse files

add redirect follow test

  • Loading branch information...
1 parent f2cd238 commit e8ed19fc3fdc31f0bc85185ddc5413b5dbdd01e1 @lxe lxe committed Jul 14, 2014
Showing with 48 additions and 0 deletions.
  1. +48 −0 test/redirects.js
View
@@ -0,0 +1,48 @@
+var tap = require("tap")
+
+var server = require("./lib/server.js")
+var common = require("./lib/common.js")
+var client = common.freshClient()
+
+var pkg = {
+ _id: "some-package@1.2.3",
+ name: "some-package",
+ version: "1.2.3"
+}
+
+tap.test("basic request", function (t) {
+ // Expect one request for { follow : false }
+ server.expect("/-/some-package/1.2.3", function (req, res) {
+ res.writeHead(301, {
+ "Location": "/some-package/1.2.3"
+ })
+ res.end("Redirecting")
+ })
+
+ // Expect 2 requests for { follow : true }
+ server.expect("/-/some-package/1.2.3", function (req, res) {
+ res.writeHead(301, {
+ "Location": "/some-package/1.2.3"
+ })
+ res.end("Redirecting")
+ })
+
+ server.expect("/some-package/1.2.3", function (req, res) {
+ res.json(pkg)
+ })
+
+ t.plan(2);
+
+ client.get("http://localhost:1337/-/some-package/1.2.3", {
+ follow: false
+ }, function(er, data) {
+ t.assert(er, "Error must be set");
+ })
+
+ client.get("http://localhost:1337/-/some-package/1.2.3", {
+ follow: true
+ }, function(er, data) {
+ t.deepEqual(data, pkg)
+ })
+})
+

0 comments on commit e8ed19f

Please sign in to comment.