Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import expect from 'expect'
function registerPre(username, password, firstName, lastName, dob) {
expect(username).toBeTruthy()
expect(password).toBeTruthy()
[username, password, firstName, lastName].forEach((arg) => expect(arg).toBeA(String))
expect(username.length).toBeGreaterThanOrEqualTo(1)
expect(username.length).toBeLessThanOrEqualTo(16)
expect(password.length).toBeGreaterThanOrEqualTo(6)
expect(username).toMatch(/[A-Za-z0-9]*/g)
expect(dob || new Date(0)).toBeA(Date)
expect(dob || new Date(0)).toBeLessThan(new Date())
}
function registerPost(res) {
expect(res).toBeTruthy()
expect(res).toIncludeKeys(['access_token', 'refresh_token', 'expires'])
return res
}
export default Object.freeze({
REGISTER: Object.freeze({ preverify: registerPre, postverify: registerPost })
})
import { BASE_URL } from '../shared/global'
import request from 'request'
import conditions from './auth-requests.conditions'
const { REGISTER } = conditions
function register(username, password, firstName, lastName, dob) {
const { preverify, postverify } = REGISTER
return new Promise((resolve, reject) => {
preverify(username, password, firstName, lastName, dob)
request.post(`${BASE_URL}/register`, { username, password, firstName, lastName, dob }, (err, res) => {
if (err) {
return reject(err)
}
resolve(postverify(res.json))
})
})
}
export register
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.