forked from andyburke/autonomous.contact
feature: require invites
This commit is contained in:
parent
8b70172493
commit
a3302d2eff
22 changed files with 385 additions and 482 deletions
56
tests/02_update_user.test.ts
Normal file
56
tests/02_update_user.test.ts
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
import { api, API_CLIENT } from '../utils/api.ts';
|
||||
import * as asserts from '@std/assert';
|
||||
import { USER } from '../models/user.ts';
|
||||
import { delete_user, EPHEMERAL_SERVER, get_ephemeral_listen_server, get_new_user, random_username } from './helpers.ts';
|
||||
import { Cookie, getSetCookies } from '@std/http/cookie';
|
||||
import { encodeBase64 } from '@std/encoding';
|
||||
import { generateTotp } from '../utils/totp.ts';
|
||||
|
||||
Deno.test({
|
||||
name: 'API - USERS - Update',
|
||||
permissions: {
|
||||
env: true,
|
||||
read: true,
|
||||
write: true,
|
||||
net: true
|
||||
},
|
||||
fn: async () => {
|
||||
let test_server_info: EPHEMERAL_SERVER | null = null;
|
||||
try {
|
||||
test_server_info = await get_ephemeral_listen_server();
|
||||
const client: API_CLIENT = api({
|
||||
prefix: '/api',
|
||||
hostname: test_server_info.hostname,
|
||||
port: test_server_info.port
|
||||
});
|
||||
|
||||
const info = await get_new_user(client);
|
||||
asserts.assert(info);
|
||||
|
||||
const user = info.user;
|
||||
asserts.assert(user);
|
||||
|
||||
const original_username = user.username;
|
||||
asserts.assertEquals(original_username, user.username);
|
||||
|
||||
const updated_user: USER = await client.fetch(`/users/${user?.id}`, {
|
||||
method: 'PUT',
|
||||
json: {
|
||||
username: random_username()
|
||||
},
|
||||
headers: info.headers
|
||||
}) as USER;
|
||||
|
||||
asserts.assert(updated_user);
|
||||
|
||||
asserts.assertNotEquals(user.username, updated_user.username);
|
||||
asserts.assertNotEquals(user.timestamps.updated, updated_user.timestamps.updated);
|
||||
|
||||
await delete_user(client, info);
|
||||
} finally {
|
||||
if (test_server_info) {
|
||||
await test_server_info?.server?.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue