Coder Social home page Coder Social logo

auth0-custom-db-testharness's People

Contributors

arcseldon avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

thenuts jmangelo

auth0-custom-db-testharness's Issues

Test Script Runs In Sandbox, but Result Is Original User Object

I am trying to run a simple test to grab a user from the database. It is running correctly in the sandbox, and I can see the expected console.logs in the web task logs, but for some reason, when it hits the callback, the result is the initial user that I passed in. I expected to see the full object from the db there. Any help greatly appreciated!

getUser:

function getByEmail(email, callback) {
  var request = require('[email protected]');
  var async = require('[email protected]');
  var auth0 = require('[email protected]')
  var userApiUrl = 'https://evidencecare-alpha.auth0.com/api/v2/users';
  var accessToken = 'ey....'

   request({
    url: userApiUrl,
    headers: {
      Authorization: 'Bearer ' + accessToken
    },
    qs: {
      search_engine: 'v2',
      q: 'email.raw:"' + email + '"'
    }
  },
    function (err, response, body) {
      if (err) return callback(err);
      if (response.statusCode !== 200) return callback(new Error(body));

      var data = JSON.parse(body);
      if (data.length > 1) {
        return callback(new Error('[!] Rule: Multiple user profiles already exist - cannot select base profile to link with'));
      }
      if (data.length === 0) {
        console.log('[-] Skipping rule');
        return callback(null, user, context);
      }
      var originalUser = data[0];

      callback(null, originalUser);
    })
}

test:

'use strict';

var fs = require('fs');
var expect = require('chai').expect;
var should = require('chai').should();
require('dotenv').config();
var testharness = require('auth0-custom-db-testharness');

// Can be whatever you need for your scripts..
var configuration = {};

var params = {
  timeout: 5,
  ca: '',
  tenant: process.env.AUTH0_TENANT,
  url: process.env.SANDBOX_URL,
  token: process.env.WEBTASK_TOKEN
};


describe('auth0-custom-db-testharness', function () {

  it('should get user by email', function (done) {

    var getUserScript = fs.readFileSync('./db-scripts/getuser.js', 'utf8');

    var loggingInUser = {
      "email": "[email protected]",
      "user_id": "123456789"
    };

    var callback = function (err, result) {
      console.log('err', err)
      should.not.exist(err);
      console.log('result in callback: ', result);
//HERE IS WHERE I GET THE loggingInUser OBJECT. I EXPECTED THE OBJECT FROM THE DB
      expect(result.user.user_id).to.equal('123456789');
      expect(result.user.email).to.equal('[email protected]');
      done();
    };

    testharness(params).getUser(getUserScript, configuration, loggingInUser, callback);

  });
});

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.