Passing tests for invite routes
This commit is contained in:
parent
212173f543
commit
05acbfa94e
@ -20,8 +20,8 @@ class Worker:
|
|||||||
|
|
||||||
self.jwt = None # never gets assigned until /login is hit
|
self.jwt = None # never gets assigned until /login is hit
|
||||||
self.basic_creds = self.__create_admin()
|
self.basic_creds = self.__create_admin()
|
||||||
self.id = self.basic_creds['id']
|
self.id = self.basic_creds['user']['id']
|
||||||
self.secret = self.basic_creds['secret']
|
self.secret = self.basic_creds['user']['secret']
|
||||||
|
|
||||||
def __create_admin(self):
|
def __create_admin(self):
|
||||||
# /home/$user/.cargo/bin/cargo <- normally
|
# /home/$user/.cargo/bin/cargo <- normally
|
||||||
@ -61,6 +61,24 @@ class Worker:
|
|||||||
opts['jwt'] = auth
|
opts['jwt'] = auth
|
||||||
return opts
|
return opts
|
||||||
|
|
||||||
|
def run_test(self, test):
|
||||||
|
# {
|
||||||
|
# 'init': [method, uri, query_string_dict],
|
||||||
|
# 'auth':jwt|none,
|
||||||
|
# 'hope': <status-code>
|
||||||
|
# 'body': <bool> # show response body or not (optional
|
||||||
|
# }
|
||||||
|
|
||||||
|
# not 'try'ing these as misconfigurations are to be cleaned up before testing
|
||||||
|
method, path, opts = test['init']
|
||||||
|
auth = test['auth']
|
||||||
|
hope = test['hope']
|
||||||
|
|
||||||
|
if 'body' in test:
|
||||||
|
self.request(method, path, auth, opts, hope, show_body=test['body'])
|
||||||
|
else:
|
||||||
|
self.request(method, path, auth, opts, hope)
|
||||||
|
|
||||||
def logs(self):
|
def logs(self):
|
||||||
ids = sorted(self.requests.keys()) # shared keys in requests/responses
|
ids = sorted(self.requests.keys()) # shared keys in requests/responses
|
||||||
for key in ids:
|
for key in ids:
|
||||||
@ -118,10 +136,10 @@ class Worker:
|
|||||||
def run(worker: Worker):
|
def run(worker: Worker):
|
||||||
VOICE_CHAN = 1
|
VOICE_CHAN = 1
|
||||||
TEXT_CHAN = 2
|
TEXT_CHAN = 2
|
||||||
|
|
||||||
# Basically every test requires a jwt to be passed in so we grab that here
|
# Basically every test requires a jwt to be passed in so we grab that here
|
||||||
# Should this fail so should nearly every other test from this point
|
# Should this fail so should nearly every other test from this point
|
||||||
req_login = worker.request('post', '/login', 'basic',{}, 200)
|
req_login = worker.request('post', '/login', 'basic',{}, 200)
|
||||||
print(worker.responses[req_login].json())
|
|
||||||
jwt = worker.responses[req_login].json()['jwt']
|
jwt = worker.responses[req_login].json()['jwt']
|
||||||
|
|
||||||
new_channel_name = time.time()
|
new_channel_name = time.time()
|
||||||
@ -144,11 +162,7 @@ def run(worker: Worker):
|
|||||||
]
|
]
|
||||||
|
|
||||||
for test in channel_tests:
|
for test in channel_tests:
|
||||||
method, path, opts = test['init']
|
worker.run_test(test)
|
||||||
auth = test['auth']
|
|
||||||
hope = test['hope']
|
|
||||||
|
|
||||||
worker.request(method, path, auth, opts, hope)
|
|
||||||
|
|
||||||
msg_chan_name = time.time()
|
msg_chan_name = time.time()
|
||||||
_id = worker.request('post', '/channels/create', jwt, {
|
_id = worker.request('post', '/channels/create', jwt, {
|
||||||
@ -220,13 +234,7 @@ def run(worker: Worker):
|
|||||||
]
|
]
|
||||||
|
|
||||||
for test in message_tests:
|
for test in message_tests:
|
||||||
method, path, opts = test['init']
|
worker.run_test(test)
|
||||||
auth = test['auth']
|
|
||||||
hope = test['hope']
|
|
||||||
if 'body' in test:
|
|
||||||
worker.request(method, path, auth, opts, hope, show_body=test['body'])
|
|
||||||
else:
|
|
||||||
worker.request(method, path, auth, opts, hope)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -238,13 +246,20 @@ def run(worker: Worker):
|
|||||||
]
|
]
|
||||||
|
|
||||||
for test in member_tests:
|
for test in member_tests:
|
||||||
method, path, opts = test['init']
|
worker.run_test(test)
|
||||||
auth = test['auth']
|
|
||||||
hope = test['hope']
|
invite_tests = [
|
||||||
if 'body' in test:
|
{'init': ['post', '/invite/create', {}], 'auth': jwt, 'hope': 200, 'body': True},
|
||||||
worker.request(method, path, auth, opts, hope, show_body=test['body'])
|
{'init': ['get', '/invite/create', {}], 'auth': jwt, 'hope': 404, 'body': True},
|
||||||
else:
|
]
|
||||||
worker.request(method, path, auth, opts, hope)
|
for test in invite_tests:
|
||||||
|
worker.run_test(test)
|
||||||
|
|
||||||
|
# ad-hoc test for joining now
|
||||||
|
invite_req_id = worker.request('post', '/invite/create', jwt, {}, 200, True)
|
||||||
|
code = worker.responses[invite_req_id].json()['id']
|
||||||
|
worker.request('get', '/join', None, {'code': code}, 200, True)
|
||||||
|
|
||||||
|
|
||||||
worker.logs()
|
worker.logs()
|
||||||
worker.test_stats()
|
worker.test_stats()
|
||||||
|
@ -122,7 +122,7 @@ impl Invite {
|
|||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
|
|
||||||
Invite {
|
Invite {
|
||||||
id: (Utc::now() + chrono::Duration::minutes(30)).timestamp(),
|
id: (Utc::now() + chrono::Duration::minutes(30)).timestamp_millis(),
|
||||||
uses,
|
uses,
|
||||||
expires
|
expires
|
||||||
}
|
}
|
||||||
|
@ -37,9 +37,8 @@ async fn valid_invite(pool: &Pool, id: BigInt) -> bool {
|
|||||||
if let Some(invite) = query {
|
if let Some(invite) = query {
|
||||||
// if expires at all
|
// if expires at all
|
||||||
if invite.expires {
|
if invite.expires {
|
||||||
let now = Utc::now().timestamp();
|
let now = Utc::now().timestamp_millis();
|
||||||
// old?
|
// old?
|
||||||
println!("{} {}", now, invite.id);
|
|
||||||
let mut valid_status = now < invite.id;
|
let mut valid_status = now < invite.id;
|
||||||
// used?
|
// used?
|
||||||
if invite.uses.is_some() && valid_status == false {
|
if invite.uses.is_some() && valid_status == false {
|
||||||
|
Loading…
Reference in New Issue
Block a user