Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F3010647
boolean.subtest.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
boolean.subtest.ts
View Options
import
assert
from
"assert"
;
import
{
withRunningApp
}
from
"../../../test_utils/with-test-app"
;
import
{
assertThrowsAsync
}
from
"../../../test_utils/assert-throws-async"
;
import
{
App
,
Collection
,
FieldTypes
,
Policies
}
from
"../../../main"
;
import
{
TestAppType
}
from
"../../../test_utils/test-app"
;
const
URL
=
"/api/v1/collections/boolseals"
;
function
extend
(
t
:
TestAppType
)
{
const
boolseals
=
new
(
class
extends
Collection
{
name
=
"boolseals"
;
fields
=
{
is_old
:
FieldTypes
.
Required
(
new
FieldTypes
.
Boolean
()),
};
defaultPolicy
=
new
Policies
.
Public
();
})();
return
class
extends
t
{
collections
=
{
...
App
.
BaseCollections
,
boolseals
,
};
};
}
describe
(
"boolean"
,
()
=>
{
it
(
"Allows to insert values considered correct"
,
async
()
=>
withRunningApp
(
extend
,
async
({
rest_api
})
=>
{
const
cases
=
[
[
true
,
true
],
[
false
,
false
],
[
"true"
,
true
],
[
"false"
,
false
],
[
"1"
,
true
],
[
"0"
,
false
],
[
1
,
true
],
[
0
,
false
],
];
for
(
const
[
field_value
,
saved_value
]
of
cases
)
{
const
{
is_old
}
=
await
rest_api
.
post
(
URL
,
{
is_old
:
field_value
,
});
assert
.
equal
(
is_old
,
saved_value
,
`While entering
${
field_value
}
, the stored value should be
${
saved_value
}
, but was
${
is_old
}
`
);
}
}));
it
(
"Doesn't let undefined in"
,
()
=>
withRunningApp
(
extend
,
async
({
rest_api
})
=>
{
await
assertThrowsAsync
(
()
=>
rest_api
.
post
(
`
${
URL
}
`
,
{
is_old
:
undefined
}),
(
error
)
=>
assert
.
deepEqual
(
error
.
response
.
data
.
data
.
is_old
.
message
,
"Missing value for field 'is_old'."
)
);
}));
it
(
"Doesn't let '' in"
,
()
=>
withRunningApp
(
extend
,
async
({
rest_api
})
=>
{
await
assertThrowsAsync
(
()
=>
rest_api
.
post
(
`
${
URL
}
`
,
{
is_old
:
""
}),
(
error
)
=>
{
assert
.
equal
(
error
.
response
.
status
,
403
);
assert
.
deepEqual
(
error
.
response
.
data
.
data
.
is_old
.
message
,
"Value '' is not boolean format."
);
}
);
}));
it
(
"Doesn't let unwelcomed values in"
,
()
=>
withRunningApp
(
extend
,
async
({
rest_api
})
=>
{
const
cases
=
[
[
null
,
"Missing value for field 'is_old'."
],
[{},
"Value '[object Object]' is not boolean format."
],
[[],
"Value '' is not boolean format."
],
[[
false
],
"Value 'false' is not boolean format."
],
[{
a
:
true
},
"Value '[object Object]' is not boolean format."
],
];
await
Promise
.
all
(
cases
.
map
(([
value
,
error_message
])
=>
assertThrowsAsync
(
()
=>
rest_api
.
post
(
`
${
URL
}
`
,
{
is_old
:
value
}),
(
error
)
=>
{
assert
.
equal
(
error
.
response
.
status
,
403
);
assert
.
deepEqual
(
error
.
response
.
data
.
data
.
is_old
.
message
,
error_message
);
}
)
)
);
}));
});
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Wed, May 7, 19:45 (1 d, 6 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
662206
Default Alt Text
boolean.subtest.ts (2 KB)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment