|
| 1 | +import db, { envelopDB, sequencerDB } from '../../../src/helpers/mysql'; |
| 2 | +import { action, verify } from '../../../src/writer/delete-subscription'; |
| 3 | + |
| 4 | +describe('writer/delete-subscription', () => { |
| 5 | + const TEST_PREFIX = 'test-delete-subscription'; |
| 6 | + |
| 7 | + afterAll(async () => { |
| 8 | + await envelopDB.queryAsync('DELETE FROM subscribers'); |
| 9 | + await envelopDB.endAsync(); |
| 10 | + await db.endAsync(); |
| 11 | + await sequencerDB.endAsync(); |
| 12 | + }); |
| 13 | + |
| 14 | + describe('verify()', () => { |
| 15 | + beforeAll(async () => { |
| 16 | + await Promise.all([ |
| 17 | + envelopDB.queryAsync( |
| 18 | + 'INSERT INTO subscribers SET address = ?, email = ?, subscriptions = ?, created = ?, verified = ?', |
| 19 | + [`${TEST_PREFIX}-0x0`, '[email protected]', '[]', 0, 0] |
| 20 | + ), |
| 21 | + envelopDB.queryAsync( |
| 22 | + 'INSERT INTO subscribers SET address = ?, email = ?, subscriptions = ?, created = ?, verified = ?', |
| 23 | + [`${TEST_PREFIX}-0x1`, '[email protected]', '[]', 0, 1] |
| 24 | + ) |
| 25 | + ]); |
| 26 | + }); |
| 27 | + |
| 28 | + it('rejects when the address is not subscribed', () => { |
| 29 | + return expect(verify({ from: '0x0' })).rejects.toEqual(`user not subscribed`); |
| 30 | + }); |
| 31 | + |
| 32 | + it('rejects when the address is not verified', () => { |
| 33 | + return expect(verify({ from: `${TEST_PREFIX}-0x0` })).rejects.toEqual(`user not subscribed`); |
| 34 | + }); |
| 35 | + |
| 36 | + it('resolves when the address is verified', () => { |
| 37 | + return expect(verify({ from: `${TEST_PREFIX}-0x1` })).resolves.toHaveProperty('address'); |
| 38 | + }); |
| 39 | + }); |
| 40 | + |
| 41 | + describe('action()', () => { |
| 42 | + const address = `${TEST_PREFIX}-0x3`; |
| 43 | + |
| 44 | + beforeAll(async () => { |
| 45 | + await Promise.all([ |
| 46 | + envelopDB.queryAsync( |
| 47 | + 'INSERT INTO subscribers SET address = ?, email = ?, subscriptions = ?, created = ?, verified = ?', |
| 48 | + [address, '[email protected]', '[]', 0, 0] |
| 49 | + ), |
| 50 | + envelopDB.queryAsync( |
| 51 | + 'INSERT INTO subscribers SET address = ?, email = ?, subscriptions = ?, created = ?, verified = ?', |
| 52 | + [address, '[email protected]', '[]', 0, 1] |
| 53 | + ) |
| 54 | + ]); |
| 55 | + }); |
| 56 | + |
| 57 | + it('deletes the subscription', async () => { |
| 58 | + await action({ from: address }); |
| 59 | + |
| 60 | + const results = await envelopDB.queryAsync('SELECT * FROM subscribers WHERE address = ?', [ |
| 61 | + address |
| 62 | + ]); |
| 63 | + |
| 64 | + // Only delete the verified subscription |
| 65 | + expect(results.length).toBe(1); |
| 66 | + expect(results[0].email).toEqual('[email protected]'); |
| 67 | + }); |
| 68 | + }); |
| 69 | +}); |
0 commit comments