// eslint-disable-next-line @typescript-eslint/no-var-requires, no-undef
const puppeteer = require('puppeteer');


describe('ecdh-aes-gcm-message', () => {
    var b1;

    beforeAll(async () => {
        b1 = await puppeteer.launch({ headless: false });
    });

    var p1;

    beforeEach(async () => {
        p1 = await b1.newPage();
        await p1.goto('http://localhost:3000/test/');
    });

    it('should be able to encrypt and decrypt a message', async () => {
        expect.assertions(1);
        const output = await p1.evaluate(() => window.tests.ecdhAesGcmMessageEncryptDecrypt('lore ipsum'));
        expect(output).toEqual({ from: 'test1', msg: 'lore ipsum' });
    });


    it('should throw when a message recieved from the same address with a different public key', async () => {
        expect.assertions(1);
        const output = await p1.evaluate(() => window.tests.ecdhAesGcmMessageEncryptDecryptSpoofing('lore ipsum'));
        expect(output).toEqual('failed to verify message');
    });

    afterEach(async () => {
        await p1.close();
    });

    afterAll(async () => {
        await b1.close();
    });
});
