refactor: zones => topics
This commit is contained in:
parent
20a5d1bc88
commit
fac8f409f4
26 changed files with 470 additions and 469 deletions
58
tests/api/topics/delete_topic.test.ts
Normal file
58
tests/api/topics/delete_topic.test.ts
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
import { api, API_CLIENT } from '../../../utils/api.ts';
|
||||
import * as asserts from '@std/assert';
|
||||
import { EPHEMERAL_SERVER, get_ephemeral_listen_server, get_new_user, set_user_permissions } from '../../helpers.ts';
|
||||
import { generateTotp } from '../../../utils/totp.ts';
|
||||
import { clear_topic_events_cache } from '../../../models/event.ts';
|
||||
|
||||
Deno.test({
|
||||
name: 'API - TOPICS - Delete',
|
||||
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 user_info = await get_new_user(client);
|
||||
|
||||
await set_user_permissions(client, user_info.user, user_info.session, [...user_info.user.permissions, 'topics.create']);
|
||||
|
||||
const new_topic = await client.fetch('/topics', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'x-session_id': user_info.session.id,
|
||||
'x-totp': await generateTotp(user_info.session.secret)
|
||||
},
|
||||
json: {
|
||||
name: 'test delete topic'
|
||||
}
|
||||
});
|
||||
|
||||
asserts.assert(new_topic);
|
||||
|
||||
const deleted_topic = await client.fetch(`/topics/${new_topic.id}`, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'x-session_id': user_info.session.id,
|
||||
'x-totp': await generateTotp(user_info.session.secret)
|
||||
}
|
||||
});
|
||||
|
||||
asserts.assert(deleted_topic);
|
||||
} finally {
|
||||
clear_topic_events_cache();
|
||||
if (test_server_info) {
|
||||
await test_server_info?.server?.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue