1 | var graph = require("../index")
|
2 | , FBConfig = require("./config").facebook
|
3 | , vows = require("vows")
|
4 | , assert = require("assert");
|
5 |
|
6 |
|
7 | var testUser1 = {}
|
8 | , testUser2 = {}
|
9 | , appAccessToken = FBConfig.appId + "|" + FBConfig.appSecret
|
10 | , wallPost = { message: "I'm gonna come at you like a spider monkey, chip" };
|
11 |
|
12 |
|
13 | vows.describe("testUser.test").addBatch({
|
14 | "Before starting a test suite": {
|
15 | topic: function () {
|
16 | return graph.setAccessToken(null);
|
17 | },
|
18 |
|
19 | "*access token* should be null": function (graph) {
|
20 | assert.isNull(graph.getAccessToken());
|
21 | }
|
22 | }
|
23 |
|
24 | }).addBatch({
|
25 | "With test users": {
|
26 | topic: function () {
|
27 |
|
28 | var testUserUrl = FBConfig.appId + "/accounts/test-users";
|
29 | var params = {
|
30 | installed: true
|
31 | , name: "Rocket Man"
|
32 | , permissions: FBConfig.scope
|
33 | , method: "post"
|
34 | , access_token: appAccessToken
|
35 | };
|
36 |
|
37 | graph.get(testUserUrl, params, this.callback);
|
38 | },
|
39 |
|
40 | "we should be able to create *user 1*": function(res) {
|
41 | assert.isNotNull(res);
|
42 | },
|
43 |
|
44 | "after creating *user 1*": {
|
45 | topic: function (res) {
|
46 | testUser1 = res;
|
47 |
|
48 |
|
49 | var testUserUrl = FBConfig.appId + "/accounts/test-users";
|
50 | var params = {
|
51 | installed: true
|
52 | , name: "Magic Man"
|
53 | , permissions: FBConfig.scope
|
54 | , method: "post"
|
55 | , access_token: appAccessToken
|
56 | };
|
57 |
|
58 | graph.get(testUserUrl, params, this.callback);
|
59 | },
|
60 |
|
61 | "we should be able to create *user 2*": function(res) {
|
62 | assert.isNotNull(res);
|
63 | },
|
64 |
|
65 | "and *user2* ": {
|
66 | topic: function (res) {
|
67 | testUser2 = res;
|
68 |
|
69 |
|
70 |
|
71 | var apiUrl = testUser1.id + "/friends/" + testUser2.id
|
72 | + "?method=post";
|
73 |
|
74 | graph.setAccessToken(testUser1.access_token);
|
75 | graph.get(encodeURI(apiUrl), this.callback);
|
76 | },
|
77 |
|
78 | "*user1* should send a friend request": function(res) {
|
79 | assert.isNotNull(res);
|
80 | },
|
81 |
|
82 | "and after a friend request has been made": {
|
83 |
|
84 | topic: function (res) {
|
85 | var apiUrl = testUser2.id + "/friends/" + testUser1.id
|
86 | + "?method=post";
|
87 |
|
88 |
|
89 |
|
90 | graph.setAccessToken(testUser2.access_token);
|
91 | graph.get(encodeURI(apiUrl), this.callback);
|
92 | },
|
93 |
|
94 | "*user2* should accept friend request": function (res) {
|
95 | assert.equal(res.data, "true");
|
96 | },
|
97 |
|
98 | " - a post on *user1*'s wall" : {
|
99 | topic: function() {
|
100 | graph.setAccessToken(testUser1.access_token);
|
101 | graph.post(testUser2.id + "/feed", wallPost, this.callback);
|
102 | },
|
103 |
|
104 | "should have a response with an id": function (res) {
|
105 | assert.include(res, 'id');
|
106 | },
|
107 |
|
108 | "when queried": {
|
109 | topic: function (res) {
|
110 | graph.get(res.id, this.callback);
|
111 | },
|
112 |
|
113 | "should be valid": function (res) {
|
114 | assert.isNotNull(res);
|
115 | assert.equal(res.message, wallPost.message);
|
116 | assert.equal(res.from.id, testUser1.id);
|
117 | }
|
118 | }
|
119 | }
|
120 | }
|
121 | }
|
122 | }
|
123 | }
|
124 | }).addBatch({
|
125 |
|
126 | "When tests are over": {
|
127 | topic: function () {
|
128 | return graph.setAccessToken(appAccessToken);
|
129 | },
|
130 |
|
131 | "after reseting the access token - ": {
|
132 | "test *user 1*": {
|
133 | topic: function (graph) {
|
134 | graph.del(testUser1.id, this.callback);
|
135 | },
|
136 |
|
137 | "should be removed": function(res){
|
138 | assert.equal(res.data, "true");
|
139 | }
|
140 | },
|
141 |
|
142 | "test *user 2*": {
|
143 | topic: function (graph) {
|
144 | graph.del(testUser2.id, this.callback);
|
145 | },
|
146 |
|
147 | "should be removed": function(res){
|
148 | assert.equal(res.data, "true");
|
149 | }
|
150 | }
|
151 | }
|
152 | }
|
153 | }).export(module);
|