Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Paste
P9045
test.js
Active
Public
Actions
Authored by
Eevans
on Sep 5 2019, 10:21 PM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Award Token
Flag For Later
Tags
None
Referenced Files
F30232211: raw.txt
Sep 5 2019, 10:21 PM
2019-09-05 22:21:57 (UTC+0)
Subscribers
None
const
assert
=
require
(
'assert'
);
const
request
=
require
(
'supertest'
);
const
TEST_URL
=
process
.
env
.
TEST_URL
;
function
randomString
(
len
)
{
var
result
=
''
;
var
chars
=
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
;
var
charsLen
=
chars
.
length
;
for
(
let
i
=
0
;
i
<
len
;
i
++
)
{
result
+=
chars
.
charAt
(
Math
.
floor
(
Math
.
random
()
*
charsLen
));
}
return
result
;
}
function
newValue
(
len
)
{
return
`KASK:V:TEST_
${
randomString
(
len
)
}
`
;
}
describe
(
'CRUD'
,
function
()
{
const
key
=
`KASK:K:TEST_
${
randomString
(
64
)
}
`
;
const
val
=
newValue
(
128
);
it
(
'creates'
,
function
()
{
// GET should 404 (key has not yet been written)
request
(
TEST_URL
)
.
get
(
`/
${
key
}
`
)
.
expect
(
404
);
request
(
TEST_URL
)
.
post
(
`/
${
key
}
`
)
.
set
(
'Content-Type'
,
'application/octet-stream'
)
.
send
(
val
)
.
expect
(
201
);
});
it
(
'reads'
,
function
()
{
request
(
TEST_URL
)
.
get
(
`/
${
key
}
`
)
.
expect
(
'Content-Type'
,
'application/octet-stream'
)
.
expect
(
200
)
.
expect
(
response
=>
assert
.
equal
(
response
.
body
,
val
));
});
it
(
'updates'
,
function
()
{
const
v
=
newValue
(
128
);
request
(
TEST_URL
)
.
post
(
`/
${
key
}
`
)
.
set
(
'Content-Type'
,
'application/octet-stream'
)
.
send
(
v
)
.
expect
(
201
);
request
(
TEST_URL
)
.
get
(
`/
${
key
}
`
)
.
expect
(
'Content-Type'
,
'application/octet-stream'
)
.
expect
(
200
)
.
expect
(
response
=>
assert
.
equal
(
response
.
body
,
v
));
});
it
(
'deletes'
,
function
()
{
request
(
TEST_URL
)
.
delete
(
`/
${
key
}
`
)
.
expect
(
204
);
request
(
TEST_URL
)
.
get
(
`/
${
key
}
`
)
.
expect
(
404
);
});
});
Event Timeline
Eevans
edited the content of this paste.
(Show Details)
Sep 5 2019, 10:21 PM
2019-09-05 22:21:57 (UTC+0)
Eevans
changed the title of this paste from untitled to
kask_test
.
Eevans
changed the title of this paste from
kask_test
to
test.js
.
Sep 5 2019, 10:22 PM
2019-09-05 22:22:19 (UTC+0)
Eevans
updated the paste's language from
autodetect
to
js
.
Log In to Comment