Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
4
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
C
CommonsPub Federated Server
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
10
Issues
10
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
1
Merge Requests
1
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Test Cases
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Bonfire
CommonsPub Federated Server
Commits
b80770c5
Commit
b80770c5
authored
Nov 09, 2020
by
Antonis Kalou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add provider/receiver for claim
parent
e8f65fdb
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
73 additions
and
7 deletions
+73
-7
lib/extensions/value_flows/claim/claim.ex
lib/extensions/value_flows/claim/claim.ex
+11
-2
lib/extensions/value_flows/claim/claims.ex
lib/extensions/value_flows/claim/claims.ex
+6
-3
lib/extensions/value_flows/simulate.ex
lib/extensions/value_flows/simulate.ex
+6
-0
test/support/value_flows/faking.ex
test/support/value_flows/faking.ex
+16
-0
test/value_flows/claim/claims_test.exs
test/value_flows/claim/claims_test.exs
+34
-2
No files found.
lib/extensions/value_flows/claim/claim.ex
View file @
b80770c5
...
...
@@ -10,6 +10,8 @@ defmodule ValueFlows.Claim do
alias
Ecto
.
Changeset
alias
CommonsPub
.
Users
.
User
alias
Measurement
.
Measure
alias
ValueFlows
.
Knowledge
.
Action
alias
ValueFlows
.
Knowledge
.
ResourceSpecification
alias
ValueFlows
.
Observation
.
EconomicEvent
...
...
@@ -52,12 +54,19 @@ defmodule ValueFlows.Claim do
@cast
@required
++
~w(note finished agreed_in created due resource_classified_as is_disabled)a
def
create_changeset
(%
User
{}
=
creator
,
attrs
)
do
def
create_changeset
(%
User
{}
=
creator
,
%{
id:
_
}
=
provider
,
%{
id:
_
}
=
receiver
,
attrs
)
do
%
__MODULE__
{}
|>
Changeset
.
cast
(
attrs
,
@cast
)
|>
Changeset
.
validate_required
(
@required
)
|>
Changeset
.
change
(
creator_id:
creator
.
id
,
is_public:
true
provider_id:
provider
.
id
,
receiver_id:
receiver
.
id
,
is_public:
true
,
# preload
provider:
provider
,
receiver:
receiver
,
creator:
creator
.
id
)
|>
common_changeset
()
end
...
...
lib/extensions/value_flows/claim/claims.ex
View file @
b80770c5
...
...
@@ -6,14 +6,17 @@ defmodule ValueFlows.Claim.Claims do
alias
ValueFlows
.
Claim
alias
ValueFlows
.
Claim
.
Queries
alias
CommonsPub
.
Meta
.
Pointers
def
one
(
filters
),
do
:
Repo
.
single
(
Queries
.
query
(
Claim
,
filters
))
def
many
(
filters
\\
[]),
do
:
{
:ok
,
Repo
.
all
(
Queries
.
query
(
Claim
,
filters
))}
def
create
(%
User
{}
=
creator
,
%{}
=
attrs
)
do
def
create
(%
User
{}
=
creator
,
%{
id:
_
}
=
provider
,
%{
id:
_
}
=
receiver
,
%{
}
=
attrs
)
do
Repo
.
transact_with
(
fn
->
with
{
:ok
,
claim
}
<-
Repo
.
insert
(
Claim
.
create_changeset
(
creator
,
attrs
))
do
{
:ok
,
%{
claim
|
creator:
creator
}}
with
{
:ok
,
provider_ptr
}
<-
Pointers
.
one
(
id:
provider
.
id
),
{
:ok
,
receiver_ptr
}
<-
Pointers
.
one
(
id:
receiver
.
id
)
do
Repo
.
insert
(
Claim
.
create_changeset
(
creator
,
provider_ptr
,
receiver_ptr
,
attrs
))
end
end
)
end
...
...
lib/extensions/value_flows/simulate.ex
View file @
b80770c5
...
...
@@ -24,6 +24,12 @@ defmodule ValueFlows.Simulate do
def
claim
(
base
\\
%{})
do
base
|>
Map
.
put_new_lazy
(
:note
,
&
summary
/
0
)
|>
Map
.
put_new_lazy
(
:agreed_in
,
&
url
/
0
)
|>
Map
.
put_new_lazy
(
:finished
,
&
bool
/
0
)
|>
Map
.
put_new_lazy
(
:created
,
&
past_datetime
/
0
)
|>
Map
.
put_new_lazy
(
:due
,
&
future_datetime
/
0
)
|>
Map
.
put_new_lazy
(
:action
,
&
action_id
/
0
)
|>
Map
.
put_new_lazy
(
:resource_classified_as
,
fn
->
some
(
1
..
5
,
&
url
/
0
)
end
)
end
def
agent_type
(),
do
:
Faker
.
Util
.
pick
([
:person
,
:organization
])
...
...
test/support/value_flows/faking.ex
View file @
b80770c5
...
...
@@ -25,6 +25,7 @@ defmodule ValueFlows.Test.Faking do
}
alias
ValueFlows
.
{
Claim
,
Proposal
# Proposals
}
...
...
@@ -60,6 +61,21 @@ defmodule ValueFlows.Test.Faking do
)
end
def
assert_claim
(%
Claim
{}
=
claim
)
do
assert_claim
(
Map
.
from_struct
(
claim
))
end
def
assert_claim
(
claim
)
do
assert_object
(
claim
,
:assert_claim
,
note:
assert_optional
(
&
assert_binary
/
1
),
agreed_in:
assert_optional
(
&
assert_binary
/
1
),
finished:
assert_optional
(
&
assert_boolean
/
1
),
created:
assert_optional
(
&
assert_datetime
/
1
),
due:
assert_optional
(
&
assert_datetime
/
1
),
resource_classified_as:
assert_optional
(
assert_list
(
&
assert_url
/
1
)),
)
end
def
assert_resource_specification
(%
ResourceSpecification
{}
=
spec
)
do
assert_resource_specification
(
Map
.
from_struct
(
spec
))
end
...
...
test/value_flows/claim/claims_test.exs
View file @
b80770c5
...
...
@@ -9,10 +9,42 @@ defmodule ValueFlows.Claim.ClaimsTest do
alias
ValueFlows
.
Claim
.
Claims
describe
"create"
do
test
"
creates a new claim with a creator
"
do
test
"
with only required parameters
"
do
user
=
fake_user!
()
provider
=
fake_user!
()
receiver
=
fake_user!
()
assert
{
:ok
,
claim
}
=
Claims
.
create
(
user
,
provider
,
receiver
,
claim
())
assert_claim
(
claim
)
assert
claim
.
creator
.
id
==
user
.
id
assert
claim
.
provider
.
id
==
provider
.
id
assert
claim
.
receiver
.
id
==
receiver
.
id
end
test
"with a context"
do
user
=
fake_user!
()
provider
=
fake_user!
()
receiver
=
fake_user!
()
attrs
=
%{
in_scope_of:
[
fake_community!
(
user
)
.
id
]
}
assert
{
:ok
,
claim
}
=
Claims
.
create
(
user
,
provider
,
receiver
,
claim
(
attrs
))
assert_claim
(
claim
)
assert
claim
.
context
.
id
==
hd
(
attrs
.
in_scope_of
)
end
test
"with measure quantities"
do
end
test
"with a resource specification"
do
end
test
"with a triggered by event"
do
assert
{
:ok
,
%
Claim
{}
=
claim
}
=
Claims
.
create
(
user
,
claim
())
end
end
end
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