tawawa / auth0-custom-db-testharness Goto Github PK
View Code? Open in Web Editor NEWDeploy, execute, and test the output of Auth0 Custom DB scripts using a webtask sandbox environment.
License: Other
Deploy, execute, and test the output of Auth0 Custom DB scripts using a webtask sandbox environment.
License: Other
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.log
s 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);
});
});
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.