Code Monkey home page Code Monkey logo

facebook-stub's Introduction

Facebook JS Stub

Include facebook-stub.js when in your testing environment, and don't include the facebook all.js

facebook-stub.js creates valid md5 sig cookie which will be passed to the server.

Overview

FacebookStub provides two global objects:

  • FB emulates the same behavior as the FB object.
  • FBWorld provides entries to get and set facebook states.

FBWorld Usage

The first think you need to do is FBWorld.setSecret(Your App Secret). This allows the creation of valid cookies.

Setting State

Then you can simulate different user states by using:

FBWorld.notLoggedIn();
FBWorld.loggedIn();
FBWorld.notConnected();
FBWorld.connected();

Connecting your app as a user

If you are not connected to the application, then when FB.login is called, you will need to respond with either

FBWorld.allowConnection(); or
FBWorld.denyConnection();

The difference between being not being logged in and connecting and being not logged in has not been flushed out yet, as it's purely a facebook state. In terms of the app, you're either connected or not.

Helper Functions

FBWorld provides you with these helper functions for debugging your application state

FBWorld.state();
FBWorld.setUid();
FBWorld.uid();
FBWorld.beingPromptedToLogin;
FBWorld.beingPromptedToConnect;

Forking Instructions

If you modify facebook-stub.js directly it will be overwritten by builder/concat. Modify src/ files only

LICENSE: MIT

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.

Simulating FB Simple Share

  // App code being tested
  FB.ui({method:'feed', etc:…}, function(){ … })

  // test pseudo code
  FBWorld.beingPromptedToShare;         //=> false
  FBWorld.beingPromptedToShareOptions;  //=> null
  FBWorld.beingPromptedToShareCallback; //=> null

  // do whatever causes the above app code to be called
  FBWorld.beingPromptedToLogin; //=> true
  FBWorld.beingPromptedToShareOptions;  //=> {method:'feed', etc:…}
  FBWorld.beingPromptedToShareCallback; //=> function(){ … }

  // simulate sharing
  FBWorld.confirmSharePrompt();
  // the callback is called here with a response stub containing a post id

  FBWorld.beingPromptedToShare;         //=> false
  FBWorld.beingPromptedToShareOptions;  //=> null
  FBWorld.beingPromptedToShareCallback; //=> null

  // OR

  // do whatever causes the above app code to be called
  FBWorld.beingPromptedToLogin; //=> true
  FBWorld.beingPromptedToShareOptions;  //=> {method:'feed', etc:…}
  FBWorld.beingPromptedToShareCallback; //=> function(){ … }

  // simulate sharing
  FBWorld.cancelSharePrompt();
  // the callback is called here with a response stub not containing a post id

  FBWorld.beingPromptedToShare;         //=> false
  FBWorld.beingPromptedToShareOptions;  //=> null
  FBWorld.beingPromptedToShareCallback; //=> null

facebook-stub's People

Contributors

mdimas avatar

Watchers

James Cloos avatar Lana Dzyuban avatar

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.