Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F9583819
text.subtest.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
text.subtest.js
View Options
const
assert
=
require
(
"assert"
);
const
locreq
=
require
(
"locreq"
)(
__dirname
);
const
axios
=
require
(
"axios"
);
const
{
with_running_app
}
=
locreq
(
"test_utils/with-test-app.js"
);
describe
(
"text"
,
()
=>
{
const
COLLECTION_NAME
=
"surnames"
;
async
function
create_test_collection
({
app
,
params
})
{
app
.
createChip
(
app
.
Sealious
.
Collection
,
{
name
:
COLLECTION_NAME
,
fields
:
[
{
name
:
"surname"
,
type
:
"text"
,
params
,
},
],
});
}
function
assert_creation_error_factory
({
base_url
,
collection
})
{
return
async
({
resource
,
message
})
=>
{
try
{
await
axios
.
post
(
`
${
base_url
}
/api/v1/collections/
${
collection
}
`
,
resource
);
throw
"This should not pass"
;
}
catch
(
e
)
{
assert
.
deepEqual
(
e
.
response
.
data
.
data
.
surname
.
message
,
message
);
}
};
}
it
(
"shouldn't allow a value that isn't a string"
,
async
()
=>
with_running_app
(
async
({
app
,
base_url
})
=>
{
await
create_test_collection
({
app
,
params
:
{}
});
const
assert_creation_error
=
assert_creation_error_factory
({
base_url
,
collection
:
COLLECTION_NAME
,
});
await
assert_creation_error
({
resource
:
{
surname
:
false
},
message
:
"Type of false is boolean, not string."
,
});
await
assert_creation_error
({
resource
:
{
surname
:
{}
},
message
:
"Type of [object Object] is object, not string."
,
});
}));
it
(
"should respect given min and max length"
,
async
()
=>
with_running_app
(
async
({
app
,
base_url
})
=>
{
await
create_test_collection
({
app
,
params
:
{
min_length
:
3
,
max_length
:
5
},
});
const
assert_creation_error
=
assert_creation_error_factory
({
base_url
,
collection
:
COLLECTION_NAME
,
});
await
assert_creation_error
({
resource
:
{
surname
:
"lo"
},
message
:
"Text 'lo' is too short, minimum length is 3 chars."
,
});
await
assert_creation_error
({
resource
:
{
surname
:
"abcdefghijk"
},
message
:
"Text 'abcdefghijk' has exceeded max length of 5 chars."
,
});
}));
it
(
"should let proper string in"
,
async
()
=>
with_running_app
(
async
({
app
,
base_url
})
=>
{
await
create_test_collection
({
app
,
params
:
{
min_length
:
3
,
max_length
:
5
},
});
return
axios
.
post
(
`
${
base_url
}
/api/v1/collections/surnames`
,
{
surname
:
"1234"
,
})
.
then
(
resp
=>
assert
.
deepEqual
(
resp
.
status
,
201
));
}));
});
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Oct 11, 10:51 (1 d, 16 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
984243
Default Alt Text
text.subtest.js (2 KB)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment