import { describe, it } from 'node:test'; import assert from 'node:assert/strict'; import { isTokenExpiringSoon } from '../services/webexOAuth.js'; import { findWebhookForRoom } from '../services/webexWebhookManager.js'; describe('isTokenExpiringSoon', () => { it('returns true when expiresAt is missing', () => { assert.equal(isTokenExpiringSoon(null), true); }); it('returns true when token expires within buffer', () => { const expiresAt = new Date(Date.now() + 2 * 60 * 1000).toISOString(); assert.equal(isTokenExpiringSoon(expiresAt, 5 * 60 * 1000), true); }); it('returns false when token is still valid beyond buffer', () => { const expiresAt = new Date(Date.now() + 30 * 60 * 1000).toISOString(); assert.equal(isTokenExpiringSoon(expiresAt, 5 * 60 * 1000), false); }); }); describe('findWebhookForRoom', () => { const targetUrl = 'https://bot.joesjavajoint.com/jiracloud/webex/messages'; const roomId = 'room-123'; const webhooks = [ { id: 'wh-1', targetUrl, resource: 'messages', event: 'created', filter: `roomId=${roomId}`, status: 'active', }, { id: 'wh-2', targetUrl: 'https://example.com/other', resource: 'messages', event: 'created', filter: `roomId=${roomId}`, status: 'active', }, ]; it('finds matching webhook by targetUrl and room filter', () => { const match = findWebhookForRoom(webhooks, { targetUrl, roomId }); assert.equal(match?.id, 'wh-1'); }); it('returns null when no webhook matches', () => { const match = findWebhookForRoom(webhooks, { targetUrl, roomId: 'other-room' }); assert.equal(match, null); }); });