Auth module refactoring in order to be reusable (#4940)

* Auth module refactoring in order to be reusable

* Ensure cache controller is properly forwarded from helpers

* Nits
This commit is contained in:
Florent Vilmart
2018-08-09 13:02:06 -04:00
committed by GitHub
parent 5d91c1057f
commit 2ae603574c
4 changed files with 169 additions and 94 deletions

View File

@@ -1,6 +1,6 @@
describe('Auth', () => {
const Auth = require('../lib/Auth.js').Auth;
const { Auth, getAuthForSessionToken } = require('../lib/Auth.js');
const Config = require('../lib/Config');
describe('getUserRoles', () => {
let auth;
let config;
@@ -90,4 +90,33 @@ describe('Auth', () => {
});
});
it('should load auth without a config', async () => {
const user = new Parse.User();
await user.signUp({
username: 'hello',
password: 'password'
});
expect(user.getSessionToken()).not.toBeUndefined();
const userAuth = await getAuthForSessionToken({
sessionToken: user.getSessionToken()
});
expect(userAuth.user instanceof Parse.User).toBe(true);
expect(userAuth.user.id).toBe(user.id);
});
it('should load auth with a config', async () => {
const user = new Parse.User();
await user.signUp({
username: 'hello',
password: 'password'
});
expect(user.getSessionToken()).not.toBeUndefined();
const userAuth = await getAuthForSessionToken({
sessionToken: user.getSessionToken(),
config: Config.get('test'),
});
expect(userAuth.user instanceof Parse.User).toBe(true);
expect(userAuth.user.id).toBe(user.id);
});
});