|
| 1 | +import test from 'node:test'; |
| 2 | +import assert from 'node:assert'; |
| 3 | +import { SelfBackendVerifier } from '../src/SelfBackendVerifier.js'; |
| 4 | +import { AttestationId } from '../src/types/types.js'; |
| 5 | + |
| 6 | +const configStorage = { |
| 7 | + getConfig: async () => ({ olderThan: 18, excludedCountries: [], ofac: false }), |
| 8 | + getActionId: async () => 'test', |
| 9 | + setConfig: async () => false, |
| 10 | +}; |
| 11 | + |
| 12 | +const construct = () => |
| 13 | + new SelfBackendVerifier( |
| 14 | + 'test-scope', |
| 15 | + 'https://example.com/api/verify', |
| 16 | + true, |
| 17 | + new Map<AttestationId, boolean>([[1, true]]), |
| 18 | + configStorage, |
| 19 | + 'uuid' |
| 20 | + ); |
| 21 | + |
| 22 | +test('constructor warns about deprecation exactly once per process', () => { |
| 23 | + const warnings: string[] = []; |
| 24 | + const originalWarn = console.warn; |
| 25 | + console.warn = (...args: unknown[]) => { |
| 26 | + warnings.push(args.map(String).join(' ')); |
| 27 | + }; |
| 28 | + try { |
| 29 | + construct(); |
| 30 | + construct(); |
| 31 | + } finally { |
| 32 | + console.warn = originalWarn; |
| 33 | + } |
| 34 | + |
| 35 | + const deprecationWarnings = warnings.filter((w) => w.includes('deprecated')); |
| 36 | + assert.equal(deprecationWarnings.length, 1); |
| 37 | + assert.ok(deprecationWarnings[0].includes('@selfxyz/enterprise-sdk')); |
| 38 | + assert.ok( |
| 39 | + deprecationWarnings[0].includes( |
| 40 | + 'https://docs.self.xyz/docs/self-enterprise/migration/from-self-pass-sdk/' |
| 41 | + ) |
| 42 | + ); |
| 43 | +}); |
0 commit comments