Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
pleroma
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
jeff
pleroma
Commits
f0ca0696
Commit
f0ca0696
authored
5 years ago
by
Alexander Strizhakov
Browse files
Options
Downloads
Patches
Plain Diff
test for valid_invite?
parent
012bb5dc
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/user_invite_token_test.exs
+96
-0
96 additions, 0 deletions
test/user_invite_token_test.exs
with
96 additions
and
0 deletions
test/user_invite_token_test.exs
0 → 100644
+
96
−
0
View file @
f0ca0696
defmodule
Pleroma
.
UserInviteTokenTest
do
use
ExUnit
.
Case
,
async:
true
use
Pleroma
.
DataCase
alias
Pleroma
.
UserInviteToken
describe
"valid_invite?/1 one time invites"
do
setup
do
invite
=
%
UserInviteToken
{
invite_type:
"one_time"
}
{
:ok
,
invite:
invite
}
end
test
"not used returns true"
,
%{
invite:
invite
}
do
invite
=
%{
invite
|
used:
false
}
assert
UserInviteToken
.
valid_invite?
(
invite
)
end
test
"used returns false"
,
%{
invite:
invite
}
do
invite
=
%{
invite
|
used:
true
}
refute
UserInviteToken
.
valid_invite?
(
invite
)
end
end
describe
"valid_invite?/1 reusable invites"
do
setup
do
invite
=
%
UserInviteToken
{
invite_type:
"reusable"
,
max_use:
5
}
{
:ok
,
invite:
invite
}
end
test
"with less uses then max use returns true"
,
%{
invite:
invite
}
do
invite
=
%{
invite
|
uses:
4
}
assert
UserInviteToken
.
valid_invite?
(
invite
)
end
test
"with equal or more uses then max use returns false"
,
%{
invite:
invite
}
do
invite
=
%{
invite
|
uses:
5
}
refute
UserInviteToken
.
valid_invite?
(
invite
)
invite
=
%{
invite
|
uses:
6
}
refute
UserInviteToken
.
valid_invite?
(
invite
)
end
end
describe
"valid_token?/1 date limited invites"
do
setup
do
invite
=
%
UserInviteToken
{
invite_type:
"date_limited"
}
{
:ok
,
invite:
invite
}
end
test
"expires today returns true"
,
%{
invite:
invite
}
do
invite
=
%{
invite
|
expires_at:
Date
.
utc_today
()}
assert
UserInviteToken
.
valid_invite?
(
invite
)
end
test
"expires yesterday returns false"
,
%{
invite:
invite
}
do
invite
=
%{
invite
|
expires_at:
Date
.
add
(
Date
.
utc_today
(),
-
1
)}
invite
=
Repo
.
insert!
(
invite
)
refute
UserInviteToken
.
valid_invite?
(
invite
)
end
end
describe
"valid_token?/1 reusable date limited invites"
do
setup
do
invite
=
%
UserInviteToken
{
invite_type:
"reusable_date_limited"
,
max_use:
5
}
{
:ok
,
invite:
invite
}
end
test
"not overdue date and less uses returns true"
,
%{
invite:
invite
}
do
invite
=
%{
invite
|
expires_at:
Date
.
utc_today
(),
uses:
4
}
assert
UserInviteToken
.
valid_invite?
(
invite
)
end
test
"overdue date and less uses returns false"
,
%{
invite:
invite
}
do
invite
=
%{
invite
|
expires_at:
Date
.
add
(
Date
.
utc_today
(),
-
1
)}
invite
=
Repo
.
insert!
(
invite
)
refute
UserInviteToken
.
valid_invite?
(
invite
)
end
test
"not overdue date with more uses returns false"
,
%{
invite:
invite
}
do
invite
=
%{
invite
|
expires_at:
Date
.
utc_today
(),
uses:
5
}
refute
UserInviteToken
.
valid_invite?
(
invite
)
end
test
"overdue date with more uses returns false"
,
%{
invite:
invite
}
do
invite
=
%{
invite
|
expires_at:
Date
.
add
(
Date
.
utc_today
(),
-
1
),
uses:
5
}
invite
=
Repo
.
insert!
(
invite
)
refute
UserInviteToken
.
valid_invite?
(
invite
)
end
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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