This repository has been archived by the owner on Dec 16, 2023. It is now read-only.
/
facebook_connect_test.coffee
88 lines (77 loc) · 2.96 KB
/
facebook_connect_test.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
{ assert, brains, Browser } = require("./helpers")
describe "Facebook Connect", ->
before (done)->
brains.get "/facebook", (req, res)->
res.send """
<html>
<head>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : "190950381025985",
status : true,
cookie : true,
xfbml : true,
oauth : true,
channelUrl : "http://localhost:3003/facebook/channel"
});
document.getElementById("connect").addEventListener("click", function(event) {
event.preventDefault();
window.FB.login(function(response) {
window.connected = response.authResponse;
})
})
var authResponse = window.FB.getAuthResponse();
if (authResponse)
window.connected = authResponse;
};
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
</script>
</head>
<body>
<div id="fb-root"></div>
<a id="connect">Connect</a>
</body>
</html>
"""
brains.ready done
describe "initial", ->
before (done)->
@browser = new Browser()
@browser.visit("http://localhost:3003/facebook")
.then =>
@browser.clickLink "Connect"
.then(done, done)
it "should show FB Connect login form", ->
assert @browser.query(".login_form_container #loginform")
describe "login", ->
before (done)->
@browser.fill("email", "---").fill("pass", "---")
@browser.pressButton("login")
.then(done, done)
it "should show permission dialog", ->
assert button = @browser.query("#platform_dialog_content #grant_clicked input")
assert.equal button.value, "Log In with Facebook"
describe "authorize", ->
before (done)->
# all.js sets a callback with a different ID on each run. Our
# HTTP/S responses were captured with the callback ID f42febd2c.
# So we cheat by using this ID and linking it to whatver callback
# was registered last.
FB = @browser.windows.get(0).FB
for id, fn of FB.XD._callbacks
FB.XD._callbacks["f42febd2c"] = fn
@browser.pressButton("Log In with Facebook")
.then =>
# Go back to the first window
@browser.windows.close()
return
.then(done, done)
it "should log user in", ->
assert.equal @browser.window.connected.userID, "100001620738919"
assert @browser.window.connected.accessToken