Skip to content

Commit

Permalink
adds test that ensure removed linked auth are actually deleted from d…
Browse files Browse the repository at this point in the history
…ocument
  • Loading branch information
flovilmart committed Mar 17, 2016
1 parent 90f170a commit 223041e
Showing 1 changed file with 38 additions and 27 deletions.
65 changes: 38 additions & 27 deletions spec/OAuth.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var OAuth = require("../src/authDataManager/OAuth1Client");
var request = require('request');
var Config = require("../src/Config");

describe('OAuth', function() {

Expand Down Expand Up @@ -28,7 +29,7 @@ describe('OAuth', function() {

it("Should properly generate request signature", (done) => {
var request = {
host: "dummy.com",
host: "dummy.com",
path: "path"
};

Expand All @@ -48,7 +49,7 @@ describe('OAuth', function() {

it("Should properly build request", (done) => {
var options = {
host: "dummy.com",
host: "dummy.com",
consumer_key: "hello",
consumer_secret: "world",
auth_token: "token",
Expand Down Expand Up @@ -86,7 +87,7 @@ describe('OAuth', function() {

it("Should fail a GET request", (done) => {
var options = {
host: "api.twitter.com",
host: "api.twitter.com",
consumer_key: "XXXXXXXXXXXXXXXXXXXXXXXXX",
consumer_secret: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
};
Expand All @@ -100,7 +101,7 @@ describe('OAuth', function() {

it("Should fail a POST request", (done) => {
var options = {
host: "api.twitter.com",
host: "api.twitter.com",
consumer_key: "XXXXXXXXXXXXXXXXXXXXXXXXX",
consumer_secret: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
};
Expand All @@ -117,7 +118,7 @@ describe('OAuth', function() {

it("Should fail a request", (done) => {
var options = {
host: "localhost",
host: "localhost",
consumer_key: "XXXXXXXXXXXXXXXXXXXXXXXXX",
consumer_secret: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
};
Expand All @@ -141,8 +142,8 @@ describe('OAuth', function() {
var provider = require("../src/authDataManager/"+providerName);
jequal(typeof provider.validateAuthData, "function");
jequal(typeof provider.validateAppId, "function");
jequal(provider.validateAuthData({}, {}).constructor, Promise.prototype.constructor);
jequal(provider.validateAppId("app", "key", {}).constructor, Promise.prototype.constructor);
jequal(provider.validateAuthData({}, {}).constructor, Promise.prototype.constructor);
jequal(provider.validateAppId("app", "key", {}).constructor, Promise.prototype.constructor);
done();
});
});
Expand Down Expand Up @@ -204,12 +205,12 @@ describe('OAuth', function() {
}
};
var headers = {'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest',
'X-Parse-REST-API-Key': 'rest',
'Content-Type': 'application/json' }

var options = {
headers: {'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest',
'X-Parse-REST-API-Key': 'rest',
'Content-Type': 'application/json' },
url: 'http://localhost:8378/1/users',
body: JSON.stringify(jsonBody)
Expand Down Expand Up @@ -248,7 +249,7 @@ describe('OAuth', function() {
done();
});
});

});

it("unlink and link with custom provider", (done) => {
Expand All @@ -266,28 +267,38 @@ describe('OAuth', function() {

model._unlinkFrom("myoauth", {
success: function(model) {

ok(!model._isLinked("myoauth"),
"User should not be linked to myoauth");
ok(!provider.synchronizedUserId, "User id should be cleared");
ok(!provider.synchronizedAuthToken, "Auth token should be cleared");
ok(!provider.synchronizedExpiration,
"Expiration should be cleared");

model._linkWith("myoauth", {
success: function(model) {
ok(provider.synchronizedUserId, "User id should have a value");
ok(provider.synchronizedAuthToken,
"Auth token should have a value");
ok(provider.synchronizedExpiration,
"Expiration should have a value");
ok(model._isLinked("myoauth"),
"User should be linked to myoauth");
done();
},
error: function(model, error) {
ok(false, "linking again should succeed");
done();
}
// make sure the auth data is properly deleted
var config = new Config(Parse.applicationId);
config.database.mongoFind('_User', {
_id: model.id
}).then((res) => {
expect(res.length).toBe(1);
expect(res[0]._auth_data_myoauth).toBeUndefined();
expect(res[0]._auth_data_myoauth).not.toBeNull();

model._linkWith("myoauth", {
success: function(model) {
ok(provider.synchronizedUserId, "User id should have a value");
ok(provider.synchronizedAuthToken,
"Auth token should have a value");
ok(provider.synchronizedExpiration,
"Expiration should have a value");
ok(model._isLinked("myoauth"),
"User should be linked to myoauth");
done();
},
error: function(model, error) {
ok(false, "linking again should succeed");
done();
}
});
});
},
error: function(model, error) {
Expand All @@ -304,4 +315,4 @@ describe('OAuth', function() {
});


})
})

0 comments on commit 223041e

Please sign in to comment.