Coder Social home page Coder Social logo

fb-zombie's Introduction

fb-zombie

This node module is focusing on creating test environment for Facebook APP development/testing. One feature of this module is to create a massive number of test users which then are made friends in terms of the specified requirement.

Installation

$ npm install fb-zombie

Documentation

Usages

### FBZombie(options) ### Initializes a new FBZombie object which is in charge of managing test users.

Arguments

  • YOUR_APP_ID - Your Facebook App ID.
  • YOUR_APP_ACCESS_TOKEN - Your Facebook App's Access Token. You APP's access token can be obtained through Facebook Graph API Explorer.

Example

FBZombie = require('fb-zombie');
fbUsers = new FBZombie('YOUR_APP_ID','YOUR_APP_ACCESS_TOKEN');
### create(total, num_of_installed, callback) ### Creates "total" number of test users, "num_of_installed" of which have APP installed. The names of each test user are retrieved from a predetermined name list in "randomname.txt". The APP has all permissions to access each test user.

Arguments

  • total - The number of test users to be created. Note: Facebook requies each APP cannot create more than 2000 test users.
  • num_of_installed - The number of test users who have APP installed.
  • callback(error, results) - The callback is called once the users creation are completed, or an error occurred.
    • error - Error object
    • results - Array of user objects, including "id", "access_token" and "login_url".

Example

fbUsers.create(100, 50, function(error, results){
  results.map(x => console.log(x));
});
### createOne(name, permission, installed, callback) ### Creates a single test user.

Arguments

  • name - The name of test user to be created.
  • permissions - Permissions for accessing this user. You can speciy "all" which means all permissions. See Here for more details.
  • callback(error, result) - The callback is called once the user creation is completed, or an error occurred.
    • error - Error object
    • result - An user object, including "id", "access_token" and "login_url".

Example

fbUsers.createOne("Alum Rock", "all", true, function(error, result){
  console.log(result);
});
### create100(callback) ### Creates 100 test users with "all" permissions and 50 test users have the APP installed. Similarly, we have: * create200(callback): Creates 200 test users with "all" permissions and 100 users have the APP installed. * create500(callback): Creates 500 test users with "all" permissions and 250 users have the APP installed. * create1000(callback): Creates 1000 test users with "all" permissions and 500 users have the APP installed. * create2000(callback): Creates 2000 test users with "all" permissions and 1000 users have the APP installed.

Attention: Facebook has a limit for graph api access. Make sure you won't reach that limit. From the Facebook documentation as of Nov. 16th, 2015, here's how rate limiting on the Graph API works:

Rate limiting is done on your Facebook AppId. If your app reaches a rate limit, all calls made for that app will be limited not just on a per-user basis. Rate limiting is calculated by taking the number of users your app had the previous day and adding today's new logins. This gives a base number of users that your app has. As an example, if your app had 10 users yesterday and 5 new logins today, that would give you a base of 15 users. This means that your app can make ((10 + 5) * 200) = 3000 API calls in any 60 minute window. See here for more details.

Arguments

  • name - The name of test user to be created.
  • permissions - Permissions for accessing this user. You can speciy "all" which means all permissions. See Here for more details.
  • callback(error, results) - The callback is called once the users creation are completed, or an error occurred.
    • error - Error object
    • results - Array of user objects, including "id", "access_token" and "login_url".

Example

fbUsers.create100(function(error, result){
  if(error) return console.log(error.message);
  console.log(result);
});
### ls(callback) ###

Retrieves all test users of this APP.

Arguments

  • callback(error, users) - The callback is called once all users are retrieved, or an error occurred.
    • error - Error object.
    • user - Array of user objects.

Example

fbUsers.ls(function(error, users){
  console.log(users);
});
### delete(num, callback) ###

Delete "num" of test users.

Arguments

  • num - The number of test users to delete.
  • callback(error, results) - The callback is called once all required users has been deleted, or an error occurred.
    • error - Error object.
    • results - Array of IDs of deleted test users.

Example

fbUsers.delete(50, function(error, results){
  console.log(results);
});
### deleteOne(id, callback) ###

Delete a test user.

Arguments

  • id - The id of the test user to delete.
  • callback(error, result) - The callback is called once all required users has been deleted, or an error occurred.
    • error - Error object.
    • result - The deleted test user object.

Example

fbUsers.deleteOne("123456789", function(error, result){
  console.log(result.name);
});
### connect(userPair, callback) ###

Connect two test users specified in "userPair". Each user must include valid "id" and user "access_token". Usually, this function is used together with "create*" functions. There is a better way to create friendship between test users using makefriends.

Arguments

  • userPair - Array of two test user objects: [user1, user2].
  • callback(error, results) - The callback is called once the two users have been connected, or an error occurred.
    • error - Error object
    • results - "userPair" is returned.

Example

var user1 = {"id":"xxxxx", "access_token":"xxxxxxxxxxx"};
var user2 = {"id":"xxxxx", "access_token":"xxxxxxxxxxx"};
fbUsers.connect([user1, user2], function(error, results){
  console.log(results);
});
### makeFriends(users, circle_num, callback) ###

Given an array of test users, create friendship between every "circle_num" users.

Arguments

  • users - Array of test user objects.
  • circle_num - Number of a group of test uesrs that will friend with each other.
  • callback(error, celebrity, results) - The callback is called once the friendship creating has been completed, or an error occurred.
    • error - Error object
    • celebrity - A test user that is a friend of all other test users.
    • results - Array of user pair that contain friends.

Example

fbUsers.create(100,80, function(error, results){
	if(error) return console.log(error.message);
	fbUsers.makeFriends(results, 10, function(err, celebrity, friends){
	    friends.map(x => console.log(x[0].id +" and "+ x[1].id + " are friends now!"));
	    console.log("total "+ friends.length+ " pairs of friends!");
	    console.log("celebrity user is: ");
	    console.log(celebrity);
	});
});

To run the test suite first invoke the following command within the repo, installing the development dependencies:

$ npm install

then modify the file test/config.js:

{
  "appID": "YOUR_APP_ID",
  "secret": "YOUR_APP_ACCESS_TOKEN"
}

Finally, run the tests:

$ npm test

License

(The MIT License)

Copyright (c) 2015 Jinpeng LV <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.