Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F996253
user-roles.test.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
user-roles.test.ts
View Options
import
assert
from
"assert"
;
import
axios
from
"axios"
;
import
{
Context
,
TestUtils
}
from
"sealious"
;
import
{
withProdApp
}
from
"../test_utils/with-prod-app.js"
;
import
{
createAdmin
,
createAUser
}
from
"../test_utils/users.js"
;
import
Users
from
"./users.js"
;
import
{
LONG_TEST_TIMEOUT
}
from
"../test_utils/webhint.js"
;
describe
(
"user-roles"
,
()
=>
{
it
(
"rejects when given an empty role"
,
async
()
=>
withProdApp
(
async
({
app
,
rest_api
})
=>
{
const
[
user
,
session
]
=
await
createAdmin
(
app
,
rest_api
);
await
TestUtils
.
assertThrowsAsync
(
async
()
=>
{
return
rest_api
.
post
(
`/api/v1/collections/user-roles`
,
{
user
:
user
.
id
,
},
session
);
},
(
e
)
=>
{
console
.
error
(
e
);
assert
.
equal
(
e
?
.
response
.
data
.
data
.
field_messages
.
role
?
.
message
,
"Missing value for field 'role'."
);
}
);
})).
timeout
(
LONG_TEST_TIMEOUT
);
it
(
"accepts correct dataset"
,
async
()
=>
withProdApp
(
async
({
app
,
base_url
,
rest_api
})
=>
{
const
[
user
,
session
]
=
await
createAdmin
(
app
,
rest_api
);
const
response
=
await
axios
.
post
(
`
${
base_url
}
/api/v1/collections/user-roles`
,
{
user
:
user
.
id
,
role
:
"admin"
,
},
session
);
assert
.
equal
(
response
.
status
,
201
);
}));
it
(
"get user roles with admin"
,
async
()
=>
withProdApp
(
async
({
app
,
rest_api
})
=>
{
const
[
user
]
=
await
createAdmin
(
app
,
rest_api
);
const
roles
=
await
Users
.
getRoles
(
new
Context
(
app
,
new
Date
().
getTime
(),
user
.
id
)
);
assert
.
ok
(
roles
.
includes
(
"admin"
));
}));
it
(
"get user with no roles"
,
async
()
=>
withProdApp
(
async
({
app
})
=>
{
const
user
=
await
createAUser
(
app
,
"normal"
);
const
roles
=
await
Users
.
getRoles
(
new
Context
(
app
,
new
Date
().
getTime
(),
user
.
id
)
);
assert
.
ok
(
roles
.
length
===
0
);
}));
it
(
"get no roles for no logged user"
,
async
()
=>
withProdApp
(
async
({
app
})
=>
{
const
roles
=
await
Users
.
getRoles
(
new
Context
(
app
,
new
Date
().
getTime
(),
null
)
);
assert
.
ok
(
roles
.
length
===
0
);
}));
});
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Tue, Dec 24, 14:02 (21 h, 12 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
557134
Default Alt Text
user-roles.test.ts (2 KB)
Attached To
Mode
rREWRITE Configurable rewriter
Attached
Detach File
Event Timeline
Log In to Comment