Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
xpub
xpub-collabra
Commits
0d37bcca
Commit
0d37bcca
authored
Jan 24, 2019
by
Giannis Kopanas
Browse files
change query start up
parent
2d5deb4d
Pipeline
#11004
passed with stages
in 6 minutes and 59 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
server/journal/src/migrations/1537450834-journals.sql
View file @
0d37bcca
...
...
@@ -25,4 +25,4 @@ INSERT INTO entities
VALUES
(
'd7009f6c-61aa-49c4-a44e-8a71072d7341'
,
'{"type": "user", "email": "author@author.com", "teams": [], "username": "author", "fragments": [], "collections": [], "passwordHash": "$2b$12$6FuyR6E5CIrU5dNCm52KKOERZW2XGeryuOeNNFwCPxhwxQ2JKLSOm"}'
);
INSERT
INTO
entities
(
id
,
"data"
)
VALUES
(
'454f40b9-bf5d-4007-8879-766a8c9bedf3'
,
'{"type": "user", "email": "admin@admin.com", "teams": [], "username": "admin", " admin": true, "fragments": [], "collections": [], "passwordHash": "$2b$12$HRzkMwUeUY.jdaO..bjK9OhHBm4JOTvq8fjzmpjAPyaYySCnIOyCO"}'
);
VALUES
(
'454f40b9-bf5d-4007-8879-766a8c9bedf3'
,
'{"type": "user", "email": "admin@admin.com", "teams": [], "username": "admin", " admin":
"
true
"
, "fragments": [], "collections": [], "passwordHash": "$2b$12$HRzkMwUeUY.jdaO..bjK9OhHBm4JOTvq8fjzmpjAPyaYySCnIOyCO"}'
);
test/authsome/integration.js
0 → 100644
View file @
0d37bcca
const
User
=
require
(
'
pubsweet-server/src/models/User
'
)
const
Collection
=
require
(
'
pubsweet-server/src/models/Collection
'
)
const
Team
=
require
(
'
pubsweet-server/src/models/Team
'
)
const
Fragment
=
require
(
'
pubsweet-server/src/models/Fragment
'
)
// Perhaps these should be exported from server together?
const
cleanDB
=
require
(
'
pubsweet-server/test/helpers/db_cleaner
'
)
const
fixtures
=
require
(
'
pubsweet-server/test/fixtures/fixtures
'
)
const
api
=
require
(
'
pubsweet-server/test/helpers/api
'
)
const
authentication
=
require
(
'
pubsweet-server/src/authentication
'
)
let
adminToken
let
userToken
let
admin
let
user
const
collectionPaper1
=
{
title
:
'
Paper 1
'
,
status
:
'
submitted
'
,
}
describe
(
'
server integration
'
,
()
=>
{
beforeEach
(
async
()
=>
{
await
cleanDB
()
admin
=
await
new
User
(
fixtures
.
adminUser
).
save
()
user
=
await
new
User
(
fixtures
.
user
).
save
()
adminToken
=
authentication
.
token
.
create
(
admin
)
userToken
=
authentication
.
token
.
create
(
user
)
})
describe
(
'
admin
'
,
()
=>
{
it
(
'
can create a collection with REST
'
,
async
()
=>
{
const
collection
=
await
api
.
collections
.
create
(
collectionPaper1
,
adminToken
)
.
expect
(
201
)
.
then
(
res
=>
res
.
body
)
expect
(
collection
.
type
).
toEqual
(
fixtures
.
collection
.
type
)
})
// it('can create a collection through GraphQL', async () => {
// const { body } = await api.graphql.query(
// `mutation($input: String) {
// createCollection(input: $input) { id, title, status }
// }`,
// {
// input: JSON.stringify(collectionPaper1),
// },
// adminToken,
// )
// expect(body.data.createCollection.title).toEqual(collectionPaper1.title)
// })
})
describe
(
'
user
'
,
()
=>
{
describe
(
'
REST
'
,
()
=>
{
it
(
'
can create users
'
,
async
()
=>
{
await
api
.
users
.
post
({
username
:
'
test
'
,
email
:
'
test3@example.com
'
,
password
:
'
testpassword
'
,
})
.
expect
(
201
)
.
then
(
res
=>
res
.
body
)
})
it
(
'
can create a collection with REST
'
,
async
()
=>
{
const
collection
=
await
api
.
collections
.
create
(
collectionPaper1
,
userToken
)
.
expect
(
201
)
.
then
(
res
=>
res
.
body
)
expect
(
collection
.
type
).
toEqual
(
fixtures
.
collection
.
type
)
})
it
(
'
can create a fragment
'
,
async
()
=>
{
await
api
.
fragments
.
post
({
fragment
:
{
version
:
3
,
fragmentType
:
'
version
'
},
token
:
userToken
,
})
.
expect
(
201
)
})
it
(
'
can create a fragment in a collection
'
,
async
()
=>
{
const
collection
=
await
new
Collection
({
title
:
'
Test
'
,
owners
:
[
user
.
id
],
}).
save
()
await
api
.
fragments
.
post
({
fragment
:
{
version
:
4
,
fragmentType
:
'
version
'
},
collection
:
{
id
:
collection
.
id
},
token
:
userToken
,
})
.
expect
(
201
)
})
it
(
'
can delete a collection they own
'
,
async
()
=>
{
const
collection
=
await
new
Collection
({
title
:
'
Test
'
,
owners
:
[
user
.
id
],
}).
save
()
await
api
.
collections
.
delete
(
collection
.
id
,
userToken
).
expect
(
200
)
})
it
(
'
can read own user
'
,
async
()
=>
{
const
userResponse
=
await
api
.
users
.
get
({
userId
:
user
.
id
,
token
:
userToken
})
.
expect
(
200
)
.
then
(
res
=>
res
.
body
)
expect
(
userResponse
.
id
).
toEqual
(
user
.
id
)
})
it
(
'
can only read certain properties of other users
'
,
async
()
=>
{
const
userResponse
=
await
api
.
users
.
get
({
userId
:
admin
.
id
,
token
:
userToken
})
.
expect
(
200
)
.
then
(
res
=>
res
.
body
)
expect
(
Object
.
keys
(
userResponse
).
sort
()).
toEqual
([
'
id
'
,
'
type
'
,
'
username
'
,
])
})
it
(
'
can list users
'
,
async
()
=>
{
const
response
=
await
api
.
users
.
get
({
token
:
userToken
})
.
expect
(
200
)
.
then
(
res
=>
res
.
body
)
expect
(
response
.
users
).
toHaveLength
(
2
)
})
})
// describe('GraphQL', () => {
// it('can create a collection with GraphQL', async () => {
// const { body } = await api.graphql.query(
// `mutation($input: String) {
// createCollection(input: $input) {
// id
// title
// status
// }
// }`,
// { input: JSON.stringify(collectionPaper1) },
// userToken,
// )
// expect(body.data.createCollection.title).toEqual(collectionPaper1.title)
// })
// it('can read a collection with GraphQL', async () => {
// const collection = await new Collection({
// title: 'Test',
// owners: [user.id],
// }).save()
// const { body } = await api.graphql.query(
// `query($id: ID) {
// collection(id: $id) {
// title
// owners {
// id
// }
// }
// }`,
// { id: collection.id },
// userToken,
// )
// expect(body).toEqual({
// data: { collection: { title: 'Test', owners: [{ id: user.id }] } },
// })
// })
// })
})
describe
(
'
managing editor
'
,
()
=>
{
describe
(
'
REST
'
,
()
=>
{
let
editorToken
let
paperA
let
paperB
beforeEach
(
async
()
=>
{
const
editor
=
await
new
User
(
Object
.
assign
({},
fixtures
.
user
,
{
username
:
'
testeditor
'
,
email
:
'
testeditor@example.com
'
,
}),
).
save
()
const
versionA1
=
await
new
Fragment
({
fragmentType
:
'
version
'
,
version
:
1
,
owners
:
[
user
.
id
],
}).
save
()
const
versionB1
=
await
new
Fragment
({
fragmentType
:
'
version
'
,
version
:
2
,
owners
:
[
admin
.
id
],
}).
save
()
paperA
=
new
Collection
({
title
:
'
Project Paper A
'
,
owners
:
[
user
.
id
],
fragments
:
[
versionA1
.
id
],
})
paperB
=
new
Collection
({
title
:
'
Project Paper B
'
,
owners
:
[
admin
.
id
],
fragments
:
[
versionB1
.
id
],
})
await
paperA
.
save
()
await
paperB
.
save
()
await
versionA1
.
updateProperties
({
collections
:
[
paperA
.
id
]
})
await
versionA1
.
save
()
await
new
Team
({
name
:
'
Managing Editors
'
,
teamType
:
'
managingEditor
'
,
members
:
[
editor
.
id
],
object
:
{
id
:
paperA
.
id
,
type
:
'
collection
'
,
},
}).
save
()
editorToken
=
authentication
.
token
.
create
(
editor
)
})
it
(
'
can list all projects (collections)
'
,
async
()
=>
{
const
collections
=
await
api
.
collections
.
list
(
editorToken
)
.
expect
(
200
)
.
then
(
res
=>
res
.
body
)
expect
(
collections
).
toHaveLength
(
1
)
})
it
(
'
can list all versions (fragments) of a project (collection)
'
,
async
()
=>
{
const
fragments
=
await
api
.
fragments
.
get
({
collection
:
paperA
,
token
:
editorToken
})
.
expect
(
200
)
.
then
(
res
=>
res
.
body
)
expect
(
fragments
).
toHaveLength
(
1
)
})
})
})
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment