-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add user routes/tests and beginning of folder -> images/sequences
couple weeks of metro ride work here... both beginning of adaptation from sequence array build by sequence adapter and some tests to add users to the db (needed for relating sequences/images to a user as well as managing account upload to external services)
- Loading branch information
1 parent
811b6cf
commit 1cbaa17
Showing
21 changed files
with
760 additions
and
1,007 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
post: require('./post') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
'use strict'; | ||
|
||
module.exports = [ | ||
require('./user').post, | ||
require('./sequence').post | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
'use strict'; | ||
|
||
const pathsSchema = require('../../schema/paths'); | ||
const Joi = require('joi'); | ||
|
||
module.exports = { | ||
method: 'POST', | ||
path: '/sequence', | ||
config: { handler: require('../../handlers/user').post } | ||
path: '/user', | ||
config: { | ||
handler: require('../../handlers/user').post, | ||
validate: { | ||
payload: Joi.object().keys({ name: Joi.string() }), | ||
failAction: async (request, h, err) => err | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
const injectDefaults = require('../config')['development'].injectDefaults; | ||
|
||
module.exports = { | ||
mergeDefaults: (request) => Object.assign(injectDefaults, request) | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// 'use strict'; | ||
|
||
// const Joi = require('joi'); | ||
// const chai = require('chai'); | ||
// const expect = chai.expect; | ||
// const server = require('../server'); | ||
// const mergeDefaults = require('../helpers').mergeDefaults; | ||
// const routes = [ | ||
// require('../../routes/sequence').post | ||
// ]; | ||
|
||
// before(async () => await server.liftOff(routes)) | ||
// describe('post', () => { | ||
// it('replies 200 when successful creating/inserting image sequences', async () => { | ||
// try { | ||
// const request = mergeDefaults({ | ||
// method: 'POST', | ||
// payload: require('../../testData/payloads.json').postSequence, | ||
// url:'/sequence' | ||
// }), | ||
// r = await server.inject(request), | ||
// statusCode = r.statusCode; | ||
|
||
// expect(statusCode).to.equal(202); | ||
// } catch (error) { | ||
// console.error(error); | ||
|
||
// } | ||
// }) | ||
// }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
handlerSpec: require('./handler'), | ||
adapterSpec: require('./adapter') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
'use strict'; | ||
|
||
const Hapi = require('hapi'); | ||
const config = require('../config')['development']; | ||
const routes = require('../routes'); | ||
const host = config.host; | ||
const server = Hapi.server({ port: 3001, host: host }) | ||
|
||
|
||
server.liftOff = async (route) => { | ||
try { | ||
server.route(route); | ||
|
||
if (!module.parent) { | ||
await server.start(); | ||
console.log(`test server started at ${server.info.uri}`) | ||
|
||
} else { | ||
await server.initialize() | ||
|
||
} | ||
|
||
} catch (error) { | ||
throw error; | ||
|
||
} | ||
} | ||
|
||
server.crashLanding = async () => { | ||
try { | ||
return await server.stop(); | ||
|
||
} catch (error) { | ||
console.error(error) | ||
|
||
} | ||
} | ||
|
||
void async function () { | ||
try { | ||
if (!module.parent) { | ||
await server.start(); | ||
|
||
} | ||
} catch (error) { | ||
console.error(error); | ||
|
||
} | ||
}() | ||
|
||
module.exports = server; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
'use strict'; | ||
|
||
const Joi = require('joi'); | ||
const chai = require('chai'); | ||
const expect = chai.expect; | ||
const server = require('../server'); | ||
const mergeDefaults = require('../helpers').mergeDefaults; | ||
const newUserPayload = require('../../testData/payloads').postUser[0]; | ||
const oldUserPayload = require('../../testData/payloads').postUser[1]; | ||
const routes = [ | ||
require('../../routes/user').post | ||
]; | ||
|
||
before(async () => await server.liftOff(routes)) | ||
describe('post', () => { | ||
it('replies 200 when successful adding user to db', async () => { | ||
try { | ||
const request = mergeDefaults({ | ||
method: 'POST', | ||
payload: newUserPayload, | ||
url:'/user' | ||
}), | ||
r = await server.inject(request), | ||
statusCode = r.statusCode; | ||
|
||
expect(statusCode).to.equal(200); | ||
|
||
} catch (error) { | ||
console.error(error); | ||
|
||
} | ||
}) | ||
it('replies 400 when unsuccessful because user already in db', async () => { | ||
try { | ||
const request = mergeDefaults({ | ||
method: 'POST', | ||
payload: oldUserPayload, | ||
url: '/user' | ||
}), | ||
r = await server.inject(request), | ||
statusCode = r.statusCode; | ||
|
||
expect(statusCode).to.equal(400); | ||
|
||
} catch (error) { | ||
console.error(error); | ||
} | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
handlerSpec: require('./handler') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict' | ||
|
||
module.exports = { | ||
postUser: require('./users')[0] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
users: require('./users') | ||
// sequences: require('./sequences'), | ||
// images: require('./images') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
'use strict'; | ||
|
||
module.exports = [ | ||
{name: 'danbjoseph'}, | ||
{name: 'giblet'} | ||
] |
Oops, something went wrong.