|
| 1 | +import { describe, expect, it } from 'vitest'; |
| 2 | +import { looksLikeGatewayMissingMessagesApi } from './gateway-compat'; |
| 3 | + |
| 4 | +describe('looksLikeGatewayMissingMessagesApi', () => { |
| 5 | + it('matches plain "not implemented"', () => { |
| 6 | + expect(looksLikeGatewayMissingMessagesApi(new Error('500 not implemented'))).toBe(true); |
| 7 | + }); |
| 8 | + |
| 9 | + it('matches "Not Implemented" with different case and spacing', () => { |
| 10 | + expect(looksLikeGatewayMissingMessagesApi(new Error('Not Implemented'))).toBe(true); |
| 11 | + }); |
| 12 | + |
| 13 | + it('matches "Messages API not supported"', () => { |
| 14 | + expect( |
| 15 | + looksLikeGatewayMissingMessagesApi(new Error('Messages API not supported on this relay')), |
| 16 | + ).toBe(true); |
| 17 | + }); |
| 18 | + |
| 19 | + it('matches "unsupported Messages API" phrasing', () => { |
| 20 | + expect(looksLikeGatewayMissingMessagesApi(new Error('unsupported messages api endpoint'))).toBe( |
| 21 | + true, |
| 22 | + ); |
| 23 | + }); |
| 24 | + |
| 25 | + it('matches bare 501 status code in text', () => { |
| 26 | + expect(looksLikeGatewayMissingMessagesApi(new Error('HTTP 501 from gateway'))).toBe(true); |
| 27 | + }); |
| 28 | + |
| 29 | + it('ignores ordinary 500 messages that do not mention not-implemented', () => { |
| 30 | + expect(looksLikeGatewayMissingMessagesApi(new Error('500 internal server error'))).toBe(false); |
| 31 | + }); |
| 32 | + |
| 33 | + it('handles non-Error inputs safely', () => { |
| 34 | + expect(looksLikeGatewayMissingMessagesApi(undefined)).toBe(false); |
| 35 | + expect(looksLikeGatewayMissingMessagesApi(null)).toBe(false); |
| 36 | + expect(looksLikeGatewayMissingMessagesApi('not implemented')).toBe(true); |
| 37 | + }); |
| 38 | +}); |
0 commit comments