bug fixes
This commit is contained in:
62
backend/tests/pg.reactionroles.test.js
Normal file
62
backend/tests/pg.reactionroles.test.js
Normal file
@@ -0,0 +1,62 @@
|
||||
const pg = require('../pg');
|
||||
|
||||
// These tests are optional: they run only if TEST_DATABASE_URL is set in env.
|
||||
// They are intentionally lightweight and will skip when not configured.
|
||||
|
||||
const TEST_DB = process.env.TEST_DATABASE_URL;
|
||||
|
||||
describe('pg reaction_roles helpers (integration)', () => {
|
||||
if (!TEST_DB) {
|
||||
test('skipped - no TEST_DATABASE_URL', () => {
|
||||
expect(true).toBe(true);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
beforeAll(async () => {
|
||||
process.env.DATABASE_URL = TEST_DB;
|
||||
await pg.initPool();
|
||||
await pg.ensureSchema();
|
||||
});
|
||||
|
||||
let created;
|
||||
|
||||
test('createReactionRole -> returns created record', async () => {
|
||||
const rr = {
|
||||
guildId: 'test-guild',
|
||||
channelId: 'test-channel',
|
||||
name: 'Test RR',
|
||||
embed: { title: 'Hello' },
|
||||
buttons: [{ label: 'One', roleId: 'role1' }]
|
||||
};
|
||||
created = await pg.createReactionRole(rr);
|
||||
expect(created).toBeTruthy();
|
||||
expect(created.id).toBeGreaterThan(0);
|
||||
expect(created.guild_id).toBe('test-guild');
|
||||
});
|
||||
|
||||
test('listReactionRoles -> includes created', async () => {
|
||||
const list = await pg.listReactionRoles('test-guild');
|
||||
expect(Array.isArray(list)).toBe(true);
|
||||
const found = list.find(r => r.id === created.id);
|
||||
expect(found).toBeTruthy();
|
||||
});
|
||||
|
||||
test('getReactionRole -> returns record by id', async () => {
|
||||
const got = await pg.getReactionRole(created.id);
|
||||
expect(got).toBeTruthy();
|
||||
expect(got.id).toBe(created.id);
|
||||
});
|
||||
|
||||
test('updateReactionRole -> updates and returns', async () => {
|
||||
const updated = await pg.updateReactionRole(created.id, { name: 'Updated' });
|
||||
expect(updated).toBeTruthy();
|
||||
expect(updated.name).toBe('Updated');
|
||||
});
|
||||
|
||||
test('deleteReactionRole -> removes record', async () => {
|
||||
await pg.deleteReactionRole(created.id);
|
||||
const after = await pg.getReactionRole(created.id);
|
||||
expect(after).toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user