Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F4637624
int.subtest.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
int.subtest.ts
View Options
import
Axios
from
"axios"
;
import
{
equal
,
deepEqual
}
from
"assert"
;
import
{
TestAppConstructor
,
withRunningApp
,
}
from
"../../../test_utils/with-test-app"
;
import
{
assertThrowsAsync
}
from
"../../../test_utils/assert-throws-async"
;
import
type
{
IntStorageParams
}
from
"./int"
;
import
{
Collection
,
FieldTypes
}
from
"../../../main"
;
import
{
TestApp
}
from
"../../../test_utils/test-app"
;
describe
(
"int"
,
()
=>
{
const
COLLECTION_NAME
=
"ages"
;
const
extend
=
(
params
?:
IntStorageParams
)
=>
(
t
:
TestAppConstructor
)
=>
{
const
col
=
new
(
class
extends
Collection
{
name
=
COLLECTION_NAME
;
fields
=
{
age
:
new
FieldTypes
.
Int
(
params
||
{}),
};
})();
return
class
extends
t
{
collections
=
{
...
TestApp
.
BaseCollections
,
[
COLLECTION_NAME
]
:
col
,
};
};
};
function
assertFormatIsNotAccepted
(
provided_value
:
any
)
{
return
withRunningApp
(
extend
(),
async
({
app
,
base_url
})
=>
{
await
assertThrowsAsync
(
()
=>
Axios
.
post
(
`
${
base_url
}
/api/v1/collections/
${
COLLECTION_NAME
}
`
,
{
age
:
provided_value
,
}
),
(
e
)
=>
{
equal
(
e
.
response
.
data
.
data
.
field_messages
.
age
.
message
,
app
.
i18n
(
"invalid_integer"
,
[
provided_value
])
);
}
);
});
}
it
(
"should allow an integer value"
,
async
()
=>
withRunningApp
(
extend
(),
async
({
base_url
})
=>
{
const
{
data
:
response
}
=
await
Axios
.
post
(
`
${
base_url
}
/api/v1/collections/
${
COLLECTION_NAME
}
`
,
{
age
:
10
,
}
);
equal
(
response
.
age
,
10
);
}));
it
(
"should allow a string which can be interpreted as an integer value"
,
async
()
=>
withRunningApp
(
extend
(),
async
({
base_url
})
=>
{
const
{
data
:
response
}
=
await
Axios
.
post
(
`
${
base_url
}
/api/v1/collections/
${
COLLECTION_NAME
}
`
,
{
age
:
"1"
,
}
);
equal
(
response
.
age
,
1
);
}));
it
(
"should respect given min and max value"
,
async
()
=>
{
const
min
=
30
;
const
max
=
50
;
await
withRunningApp
(
extend
({
min
:
min
,
max
:
max
}),
async
({
app
,
base_url
})
=>
{
let
age
=
29
;
await
assertThrowsAsync
(
()
=>
Axios
.
post
(
`
${
base_url
}
/api/v1/collections/
${
COLLECTION_NAME
}
`
,
{
age
:
age
,
}
),
(
e
)
=>
{
equal
(
e
.
response
?
.
data
?
.
data
?
.
field_messages
.
age
.
message
,
app
.
i18n
(
"too_small_integer"
,
[
age
,
min
])
);
}
);
age
=
51
;
await
assertThrowsAsync
(
()
=>
Axios
.
post
(
`
${
base_url
}
/api/v1/collections/
${
COLLECTION_NAME
}
`
,
{
age
:
age
,
}
),
(
e
)
=>
{
equal
(
e
.
response
?
.
data
?
.
data
?
.
field_messages
.
age
.
message
,
app
.
i18n
(
"too_big_integer"
,
[
age
,
max
])
);
}
);
}
);
});
it
(
"should let proper a string as an integer value in the defined range"
,
async
()
=>
withRunningApp
(
extend
({
min
:
-
2
,
max
:
6
}),
async
({
base_url
})
=>
{
return
Axios
.
post
(
`
${
base_url
}
/api/v1/collections/
${
COLLECTION_NAME
}
`
,
{
age
:
"-1"
,
}
).
then
((
response
)
=>
deepEqual
(
response
.
status
,
201
));
}));
it
(
"should allow a largest integer value"
,
async
()
=>
withRunningApp
(
extend
(),
async
({
base_url
})
=>
{
const
{
data
:
response
}
=
await
Axios
.
post
(
`
${
base_url
}
/api/v1/collections/
${
COLLECTION_NAME
}
`
,
{
age
:
Number
.
MAX_SAFE_INTEGER
,
}
);
equal
(
response
.
age
,
Number
.
MAX_SAFE_INTEGER
);
}));
it
(
"should allow a smallest integer value provided as a string value"
,
async
()
=>
withRunningApp
(
extend
(),
async
({
base_url
})
=>
{
const
{
data
:
response
}
=
await
Axios
.
post
(
`
${
base_url
}
/api/v1/collections/
${
COLLECTION_NAME
}
`
,
{
age
:
Number
.
MIN_SAFE_INTEGER
.
toString
(),
}
);
equal
(
response
.
age
,
Number
.
MIN_SAFE_INTEGER
);
}));
it
(
"should allow a string with whitespace characters which can be interpreted as an integer value"
,
async
()
=>
withRunningApp
(
extend
(),
async
({
base_url
})
=>
{
const
{
data
:
response
}
=
await
Axios
.
post
(
`
${
base_url
}
/api/v1/collections/
${
COLLECTION_NAME
}
`
,
{
age
:
" -20 "
,
}
);
equal
(
response
.
age
,
-
20
);
}));
it
(
"shouldn't allow a boolean value"
,
async
()
=>
await
assertFormatIsNotAccepted
(
true
));
it
(
"shouldn't allow an object value"
,
async
()
=>
await
assertFormatIsNotAccepted
({}));
it
(
"shouldn't allow a string which cannot be interpreted as an integer value"
,
async
()
=>
await
assertFormatIsNotAccepted
(
"2013ffff"
));
it
(
"shouldn't allow a float number which cannot be interpreted as an integer value"
,
async
()
=>
await
assertFormatIsNotAccepted
(
1.2
));
it
(
"shouldn't allow a float number inserted as a string which cannot be interpreted as an integer value"
,
async
()
=>
await
assertFormatIsNotAccepted
(
"1.2"
));
});
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Tue, May 27, 23:48 (1 d, 20 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
625319
Default Alt Text
int.subtest.ts (4 KB)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment