diff --git a/modules/core/graph/resolvers/commits.js b/modules/core/graph/resolvers/commits.js index 3e17f15a6..aa676faec 100644 --- a/modules/core/graph/resolvers/commits.js +++ b/modules/core/graph/resolvers/commits.js @@ -39,7 +39,8 @@ module.exports = { }, async commit( parent, args, context, info ) { - throw new ApolloError( 'not implemented' ) + let c = await getCommitById( { id: args.id } ) + return c } }, diff --git a/modules/core/graph/resolvers/user.js b/modules/core/graph/resolvers/user.js index a0f225ddb..cb5a6853d 100644 --- a/modules/core/graph/resolvers/user.js +++ b/modules/core/graph/resolvers/user.js @@ -15,6 +15,7 @@ module.exports = { }, async user( parent, args, context, info ) { + await validateServerRole( context, 'server:user' ) if ( !args.id ) diff --git a/modules/core/services/tokens.js b/modules/core/services/tokens.js index 9a8ed68f9..d34d7c699 100644 --- a/modules/core/services/tokens.js +++ b/modules/core/services/tokens.js @@ -16,10 +16,10 @@ const ServerAppsScopes = ( ) => knex( 'server_apps_scopes' ) module.exports = { /* - + Tokens Note: tokens are composed of a 10 char token id and a 32 char token string. - The token string is smoked, salted and hashed and stored in the database. + The token string is smoked, salted and hashed and stored in the database. */ @@ -54,12 +54,12 @@ module.exports = { return { id: tokenId, token: tokenId + tokenString } }, - // Creates a personal access token for a user with a set of given scopes. + // Creates a personal access token for a user with a set of given scopes. async createPersonalAccessToken( userId, name, scopes, lifespan ) { let { id, token } = await module.exports.createToken( { userId, name, scopes, lifespan } ) - // Store the relationship + // Store the relationship await PersonalApiTokens( ).insert( { userId: userId, tokenId: id } ) return token @@ -130,4 +130,4 @@ module.exports = { async getTokenScopes( tokenId ) { } -} \ No newline at end of file +} diff --git a/modules/core/tests/graph.spec.js b/modules/core/tests/graph.spec.js index f8150758c..99b82237a 100644 --- a/modules/core/tests/graph.spec.js +++ b/modules/core/tests/graph.spec.js @@ -672,6 +672,8 @@ describe( 'GraphQL API Core', ( ) => { expect( res2.body.data.stream.branch.commits.items[ 0 ] ).to.have.property( 'createdAt' ) } ) + let commitList + it( 'should retrieve all stream commits', async ( ) => { let query = ` query { @@ -696,6 +698,8 @@ describe( 'GraphQL API Core', ( ) => { expect( res.body.data.stream.commits.items.length ).to.equal( 10 ) expect( res.body.data.stream.commits.totalCount ).to.equal( 12 ) + commitList = res.body.data.stream.commits.items + let query2 = ` query { stream( id: "${ts1}" ) { @@ -714,8 +718,6 @@ describe( 'GraphQL API Core', ( ) => { ` const res2 = await sendRequest( userA.token, { query: query2 } ) - console.log( res2.body.errors ) - console.log( res2.body.data.stream.commits ) expect( res2 ).to.be.json expect( res2.body.errors ).to.not.exist @@ -724,10 +726,11 @@ describe( 'GraphQL API Core', ( ) => { } ) it( 'should retrieve a stream commit', async ( ) => { - const res = await sendRequest( userA.token, { query: `query { stream(id:"${ts1}") { commit(id:"${c2.id}") { id description data } } }` } ) + const res = await sendRequest( userA.token, { query: `query { stream( id:"${ts1}" ) { commit( id: "${commitList[ 0 ].id}" ) { id message referencedObject } } }` } ) + expect( res ).to.be.json expect( res.body.errors ).to.not.exist - expect( res.body.data.stream.commit.description ).to.equal( 'test second commit' ) + expect( res.body.data.stream.commit.message ).to.equal( 'what a message for commit number 19' ) // should be the last created one } ) } )