Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F995933
user-referenced-in-field.test.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
user-referenced-in-field.test.ts
View Options
import
assert
from
"assert"
;
import
{
TestAppConstructor
,
withRunningApp
}
from
"../../test_utils/with-test-app.js"
;
import
{
Collection
,
FieldTypes
,
Policies
}
from
"../../main.js"
;
import
{
TestApp
}
from
"../../test_utils/test-app.js"
;
function
extend
(
t
:
TestAppConstructor
)
{
const
pets
=
new
(
class
extends
Collection
{
name
=
"pets"
;
fields
=
{
name
:
new
FieldTypes
.
Text
(),
owner
:
new
FieldTypes
.
SingleReference
(
"users"
),
};
policies
=
{
create
:
new
Policies
.
Public
(),
};
defaultPolicy
=
new
Policies
.
UserReferencedInField
(
"owner"
);
})();
return
class
extends
t
{
collections
=
{
...
TestApp
.
BaseCollections
,
pets
,
};
};
}
describe
(
"user-referenced-in-field"
,
()
=>
{
it
(
"should deny if the user isn't the one referenced in the field and allow if it is"
,
async
()
=>
withRunningApp
(
extend
,
async
({
app
,
rest_api
})
=>
{
for
(
let
username
of
[
"Alice"
,
"Bob"
])
{
const
user
=
await
app
.
collections
.
users
.
suCreate
({
username
,
password
:
"password"
,
});
await
app
.
collections
.
pets
.
suCreate
({
name
:
`
${
username
}
's pet`
,
owner
:
user
.
id
,
});
}
const
alice_session
=
await
rest_api
.
login
({
username
:
"Alice"
,
password
:
"password"
,
});
const
{
items
}
=
await
rest_api
.
get
(
"/api/v1/collections/pets"
,
alice_session
);
assert
.
strictEqual
(
items
.
length
,
1
);
assert
.
strictEqual
(
items
[
0
].
name
,
"Alice's pet"
);
}));
});
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Tue, Dec 24, 01:48 (22 h, 6 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
556035
Default Alt Text
user-referenced-in-field.test.ts (1 KB)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment