Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F1263274
and.subtest.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
and.subtest.ts
View Options
import
assert
from
"assert"
;
import
Bluebird
from
"bluebird"
;
import
{
App
,
Collection
}
from
"../../../main"
;
import
{
with_running_app
}
from
"../../../../test_utils/with-test-app"
;
import
create_strategies
from
"../../../../test_utils/access-strategy-types/create_strategies_with_complex_pipeline"
;
describe
(
"AndAccessStrategy"
,
()
=>
{
async
function
setup
(
app
:
App
)
{
Collection
.
fromDefinition
(
app
,
{
name
:
"numbers"
,
fields
:
[
{
name
:
"number"
,
type
:
"int"
,
},
],
});
create_strategies
.
allow_deny
(
app
);
const
collections
=
[
{
name
:
"collection-and(nested-and(allow, public), nested-or(allow, noone))"
,
strategies
:
[
[
"and"
,
[
"complex-allow-pipeline"
,
"public"
]],
[
"or"
,
[
"complex-allow-pipeline"
,
"noone"
]],
],
},
{
name
:
"collection-and(complex-allow-pipeline, noone)"
,
strategies
:
[
"complex-allow-pipeline"
,
"noone"
],
},
{
name
:
"collection-and(complex-allow-pipeline, public)"
,
strategies
:
[
"complex-allow-pipeline"
,
"public"
],
},
{
name
:
"collection-and(complex-deny-pipeline, public)"
,
strategies
:
[
"complex-deny-pipeline"
,
"public"
],
},
];
for
(
const
{
name
,
strategies
}
of
collections
)
{
Collection
.
fromDefinition
(
app
,
{
name
:
name
,
fields
:
[
{
name
:
"number"
,
type
:
"single_reference"
,
params
:
{
collection
:
"numbers"
},
required
:
true
,
},
],
access_strategy
:
{
show
:
[
"and"
,
strategies
],
create
:
"public"
,
},
});
}
let
numbers
=
await
Bluebird
.
map
([
0
,
1
,
2
],
(
n
)
=>
app
.
run_action
(
new
app
.
Sealious
.
SuperContext
(),
[
"collections"
,
"numbers"
],
"create"
,
{
number
:
n
}
)
);
for
(
const
number
of
numbers
)
{
await
Bluebird
.
map
(
collections
,
({
name
})
=>
app
.
run_action
(
new
app
.
Sealious
.
SuperContext
(),
[
"collections"
,
name
],
"create"
,
{
number
:
number
.
id
}
)
);
}
}
it
(
"return everything for collection-and(nested-and(allow, public), nested-or(allow, noone))"
,
()
=>
with_running_app
(
async
({
app
,
rest_api
})
=>
{
await
setup
(
app
);
return
rest_api
.
get
(
"/api/v1/collections/collection-and(nested-and(allow, public), nested-or(allow, noone))"
)
.
then
(({
items
}
:
{
items
:
any
[]
})
=>
assert
.
equal
(
items
.
length
,
3
)
);
}));
it
(
"returns nothing for and(complex-allow-pipeline, noone)"
,
()
=>
with_running_app
(
async
({
app
,
rest_api
})
=>
{
await
setup
(
app
);
return
rest_api
.
get
(
"/api/v1/collections/collection-and(complex-allow-pipeline, noone)"
)
.
then
(({
items
}
:
{
items
:
any
[]
})
=>
assert
.
equal
(
items
.
length
,
0
)
);
}));
it
(
"returns everything for and(complex-allow-pipeline, public)"
,
()
=>
with_running_app
(
async
({
app
,
rest_api
})
=>
{
await
setup
(
app
);
return
rest_api
.
get
(
"/api/v1/collections/collection-and(complex-allow-pipeline, public)"
)
.
then
(({
items
}
:
{
items
:
any
[]
})
=>
assert
.
equal
(
items
.
length
,
3
)
);
}));
it
(
"returns nothing for and(complex-deny-pipeline, public)"
,
()
=>
with_running_app
(
async
({
app
,
rest_api
})
=>
{
await
setup
(
app
);
return
rest_api
.
get
(
"/api/v1/collections/collection-and(complex-deny-pipeline, public)"
)
.
then
(({
items
}
:
{
items
:
any
[]
})
=>
assert
.
equal
(
items
.
length
,
0
)
);
}));
});
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Fri, Jan 24, 16:50 (2 h, 47 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
601460
Default Alt Text
and.subtest.ts (3 KB)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment