|
| 1 | +/** |
| 2 | + * reserved-commands.test.ts - test sqlitecloud reserved commands |
| 3 | + */ |
| 4 | + |
| 5 | +import { |
| 6 | + _, |
| 7 | + SQLiteCloudError, |
| 8 | + SQLiteCloudRowset, |
| 9 | + SQLiteCloudConnection, |
| 10 | + SQLiteCloudTlsConnection, |
| 11 | + CHINOOK_DATABASE_URL, |
| 12 | + parseconnectionstring, |
| 13 | + getConnection, |
| 14 | + connUsername, |
| 15 | + randomName, |
| 16 | + randomDate, |
| 17 | + randomBool, |
| 18 | + date, |
| 19 | + ip, |
| 20 | + uuid, |
| 21 | + bool, |
| 22 | + colseq, |
| 23 | + screaming_snake_case, |
| 24 | + regex_IP_UUID_N, |
| 25 | + test |
| 26 | +} from './shared' |
| 27 | + |
| 28 | +describe.skip.each([['example.com', 'chinook.sqlite', 'artists', 3, _, '', true]])('webhook', (url_or_code, database, table, mask, options, secret, ok) => { |
| 29 | + let generated_secret = '' |
| 30 | + |
| 31 | + it(`should${ok ? '' : "n't"} add`, done => { |
| 32 | + const chinook = getConnection() |
| 33 | + chinook.sendCommands( |
| 34 | + `ADD WEBHOOK ${url_or_code}`, |
| 35 | + test(done, chinook, ok, (r: any) => (generated_secret = r)) |
| 36 | + ) |
| 37 | + }) |
| 38 | + |
| 39 | + it(`should${ok ? '' : "n't"} add with secret`, done => { |
| 40 | + const chinook = getConnection() |
| 41 | + chinook.sendCommands( |
| 42 | + `ADD WEBHOOK ${url_or_code}${database ? `DATABASE ${database}` : ''}${table ? `TABLE ${table}` : ''}${mask ? `MASK ${mask}` : ''}${options ? `OPTIONS ${options}` : ''} SECRET ${secret}`, |
| 43 | + test(done, chinook, ok) |
| 44 | + ) |
| 45 | + }) |
| 46 | + |
| 47 | + let id = 0 |
| 48 | + |
| 49 | + it(`should${ok ? '' : "n't"} list`, done => { |
| 50 | + const chinook = getConnection() |
| 51 | + chinook.sendCommands( |
| 52 | + `LIST WEBHOOKS`, |
| 53 | + test( |
| 54 | + done, |
| 55 | + chinook, |
| 56 | + ok, |
| 57 | + { |
| 58 | + id: expect.any(Number), |
| 59 | + action: url_or_code, |
| 60 | + databasename: database, |
| 61 | + tablename: table, |
| 62 | + mask: mask, |
| 63 | + options: options, |
| 64 | + secret: secret |
| 65 | + }, |
| 66 | + (r: any) => (id = r[1].id) |
| 67 | + ) |
| 68 | + ) |
| 69 | + }) |
| 70 | + |
| 71 | + it(`should${ok ? '' : "n't"} remove`, done => { |
| 72 | + const chinook = getConnection() |
| 73 | + chinook.sendCommands(`REMOVE WEBHOOK ${id}`, test(done, chinook, ok)) |
| 74 | + }) |
| 75 | + |
| 76 | + it(`shouldn't list removed`, done => { |
| 77 | + const chinook = getConnection() |
| 78 | + chinook.sendCommands( |
| 79 | + `LIST WEBHOOKS`, |
| 80 | + test( |
| 81 | + done, |
| 82 | + chinook, |
| 83 | + false, |
| 84 | + { |
| 85 | + id: expect.any(Number), |
| 86 | + action: url_or_code, |
| 87 | + databasename: database, |
| 88 | + tablename: table, |
| 89 | + mask: mask, |
| 90 | + options: options, |
| 91 | + secret: secret |
| 92 | + }, |
| 93 | + (r: any) => (id = r.id) |
| 94 | + ) |
| 95 | + ) |
| 96 | + }) |
| 97 | +}) |
0 commit comments