var common = require("./common"),
    test = require("tap").test;

// We can use a fake audience in tests
var audience = "http://example.org:80";

test("basic login test with defaults", function(t) {
  t.plan(4);

  common.createServer({audience: audience}, function(err, app) {
    common.getAssertionFor(audience, function(err, assertionData) {
      var host = "http://localhost:" + app.address().port;
      var localVerifier = host + "/persona/verify";

      common.verifyAssertion(localVerifier, assertionData.assertion, function(err, verifiedData) {
        t.equal(verifiedData.status, "okay");
        t.equal(verifiedData.email, assertionData.email);
        common.getSessionData(host + "/session", function(err, body) {
          t.equal(body.email, assertionData.email);
          common.logout(host + "/persona/logout", function(err, body) {
            t.equal(body.status, "okay");
            t.end();
            app.close();
          });
        });
      });
    });
  });
});

test("no audience set", function(t) {
  t.plan(2);

  common.createServer({}, function(err, app) {
    common.getAssertionFor(audience, function(err, assertionData) {
      var localVerifier = "http://localhost:" + app.address().port + "/persona/verify";

      common.verifyAssertion(localVerifier, assertionData.assertion, function(err, verifiedData) {
        t.equal(verifiedData.status, "failure");
        t.equal(verifiedData.reason, "need assertion and audience");
        t.end();
        app.close();
      });
    });
  });
});

test("changed verify path", function(t) {
  t.plan(2);

  common.createServer({audience: audience, verifyPath: "/browserid/verify"}, function(err, app) {
    common.getAssertionFor(audience, function(err, assertionData) {
      var localVerifier = "http://localhost:" + app.address().port + "/browserid/verify";

      common.verifyAssertion(localVerifier, assertionData.assertion, function(err, verifiedData) {
        t.equal(verifiedData.status, "okay");
        t.equal(verifiedData.email, assertionData.email);
        t.end();
        app.close();
      });
    });
  });
});

@@ -206,9 +206,9 @@
 lan(
-4
+5
 );%0A%0A
@@ -884,32 +884,150 @@
 tatus, %22okay%22);%0A
+            common.getSessionData(host + %22/session%22, function(err, body) %7B%0A              t.equal(body.email, null);%0A  
             t.en
@@ -1035,32 +1035,34 @@
 ();%0A            
+ 
+ 
 app.close();%0A   
@@ -1054,24 +1054,39 @@
 pp.close();%0A
+            %7D)%0A
           %7D)

make sure session is cleared after logout