Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
pubsweet
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julien Tremblay McLellan
pubsweet
Commits
a10e81cf
Commit
a10e81cf
authored
6 years ago
by
Jure
Browse files
Options
Downloads
Patches
Plain Diff
feat: add team relationship to user and test it
parent
dfb2cce8
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
packages/components/model-team/test/team_test.js
+33
-74
33 additions, 74 deletions
packages/components/model-team/test/team_test.js
packages/components/model-user/src/user.js
+20
-0
20 additions, 0 deletions
packages/components/model-user/src/user.js
with
53 additions
and
74 deletions
packages/components/model-team/test/team_test.js
+
33
−
74
View file @
a10e81cf
...
@@ -9,9 +9,22 @@ process.env.NODE_CONFIG = `{"pubsweet":{
...
@@ -9,9 +9,22 @@ process.env.NODE_CONFIG = `{"pubsweet":{
const
{
model
:
Team
}
=
require
(
'
../src
'
)
const
{
model
:
Team
}
=
require
(
'
../src
'
)
const
{
model
:
User
}
=
require
(
'
@pubsweet/model-user
'
)
const
{
model
:
User
}
=
require
(
'
@pubsweet/model-user
'
)
const
{
dbCleaner
}
=
require
(
'
pubsweet-server/test
'
)
const
{
dbCleaner
}
=
require
(
'
pubsweet-server/test
'
)
const
createTeamWithMember
=
async
()
=>
{
const
user
=
await
new
User
({
email
:
'
some@example.com
'
,
username
:
'
test
'
,
}).
save
()
const
newTeam
=
await
new
Team
({
name
:
'
Test
'
,
role
:
'
testRole
'
}).
save
()
const
team
=
await
Team
.
query
().
findById
(
newTeam
.
id
)
await
team
.
$relatedQuery
(
'
members
'
).
relate
(
user
.
id
)
return
{
user
,
team
}
}
describe
(
'
Team
'
,
()
=>
{
describe
(
'
Team
'
,
()
=>
{
beforeEach
(
async
()
=>
{
beforeEach
(
async
()
=>
{
await
dbCleaner
()
await
dbCleaner
()
...
@@ -43,83 +56,29 @@ describe('Team', () => {
...
@@ -43,83 +56,29 @@ describe('Team', () => {
})
})
it
(
'
can have some members
'
,
async
()
=>
{
it
(
'
can have some members
'
,
async
()
=>
{
const
user
=
await
new
User
({
const
newTeam
=
(
await
createTeamWithMember
()).
team
email
:
'
some@example.com
'
,
const
team
=
await
Team
.
query
()
username
:
'
test
'
,
}).
save
()
const
newTeam
=
await
new
Team
({
name
:
'
Test
'
,
role
:
'
testRole
'
}).
save
()
let
team
=
await
Team
.
query
().
findById
(
newTeam
.
id
)
await
team
.
$relatedQuery
(
'
members
'
).
relate
(
user
.
id
)
team
=
await
Team
.
query
()
.
findById
(
newTeam
.
id
)
.
findById
(
newTeam
.
id
)
.
eager
(
'
members
'
)
.
eager
(
'
members
'
)
expect
(
team
.
members
).
toHaveLength
(
1
)
expect
(
team
.
members
).
toHaveLength
(
1
)
})
})
// it('can be found by property', async () => {
it
(
'
deletes memberships after team is deleted
'
,
async
()
=>
{
// await new Manuscript({ title: 'Test' }).save()
const
{
team
,
user
}
=
await
createTeamWithMember
()
// const team = await Manuscript.findOneByField('title', 'Test')
// expect(team.title).toEqual('Test')
let
foundUser
=
await
User
.
query
()
.
findById
(
user
.
id
)
// let manuscripts = await Manuscript.findByField('title', 'Test')
.
eager
(
'
teams
'
)
// expect(manuscripts[0].title).toEqual('Test')
expect
(
foundUser
.
teams
).
toHaveLength
(
1
)
// async function findMissing() {
// await Manuscript.findOneByField('title', 'Does not exist')
await
Team
.
query
().
deleteById
(
team
.
id
)
// }
foundUser
=
await
User
.
query
()
// await expect(findMissing()).rejects.toThrow('Object not found')
.
findById
(
user
.
id
)
.
eager
(
'
teams
'
)
// manuscripts = await Manuscript.findByField('title', 'Does not exist')
// expect(manuscripts).toEqual([])
expect
(
foundUser
.
teams
).
toHaveLength
(
0
)
// })
})
// it('can not be saved with non-valid properties', async () => {
// async function createNonValidManuscript() {
// await new Manuscript({ mumbo: 'jumbo' }).save()
// }
// await expect(createNonValidManuscript()).rejects.toThrow(
// 'mumbo: is an invalid additional property',
// )
// })
// it('can assign to special properties', () => {
// const manuscript = new Manuscript()
// manuscript['#id'] = 'idref'
// })
// it('takes schema specified in config into account', async () => {
// const manuscript = new Manuscript({ configField: 'hello' })
// expect(manuscript.configField).toEqual('hello')
// })
// it('can save new entity with known ID', async () => {
// const id = '1838d074-fb9d-4ed6-9c63-39e6bc7429ce'
// const manuscript = await new Manuscript({ id }).save()
// expect(manuscript.id).toEqual(id)
// })
// it('old data does not overwrite new', async () => {
// // T0 - start time (A == B)
// let manuscriptA = await new Manuscript({ title: 'T0' }).save()
// expect(manuscriptA.title).toEqual('T0')
// const manuscriptB = await Manuscript.find(manuscriptA.id)
// // T1 - B is changed (not saved)
// manuscriptB.title = 'T1'
// // T2 - A is changed and saved
// manuscriptA.title = 'T2'
// manuscriptA = await manuscriptA.save()
// expect(manuscriptA.updated).not.toBe(manuscriptB.updated)
// // T4 - now save B, this should throw as `updated` is older than current.
// await expect(manuscriptB.save()).rejects.toThrow(
// 'Data Integrity Error property updated',
// )
// })
})
})
This diff is collapsed.
Click to expand it.
packages/components/model-user/src/user.js
+
20
−
0
View file @
a10e81cf
...
@@ -24,6 +24,26 @@ class User extends BaseModel {
...
@@ -24,6 +24,26 @@ class User extends BaseModel {
return
'
users
'
return
'
users
'
}
}
static
get
relationMappings
()
{
return
{
teams
:
{
relation
:
BaseModel
.
ManyToManyRelation
,
modelClass
:
require
.
resolve
(
'
@pubsweet/model-team/src/team
'
),
join
:
{
from
:
'
users.id
'
,
through
:
{
modelClass
:
require
.
resolve
(
'
@pubsweet/model-team-member/src/team_member
'
,
),
from
:
'
team_members.user_id
'
,
to
:
'
team_members.team_id
'
,
},
to
:
'
teams.id
'
,
},
},
}
}
static
get
schema
()
{
static
get
schema
()
{
return
{
return
{
properties
:
{
properties
:
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment