var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import { EventsGet } from '../../src/interfaces/events-get.js';
import { expect } from 'chai';
import { Jws } from '../../src/index.js';
import { Message } from '../../src/core/message.js';
import { TestDataGenerator } from '../utils/test-data-generator.js';
describe('EventsGet Message', () => {
    if (process.env.TESTSOFF === 'true') {
        return;
    }
    describe('create', () => {
        it('creates an EventsGet message', () => __awaiter(void 0, void 0, void 0, function* () {
            const alice = yield TestDataGenerator.generatePersona();
            const eventsGet = yield EventsGet.create({
                watermark: 'yolo',
                authorizationSignatureInput: yield Jws.createSignatureInput(alice)
            });
            const { message } = eventsGet;
            expect(message.descriptor).to.exist;
            expect(message.descriptor.watermark).to.equal('yolo');
            expect(message.authorization).to.exist;
        }));
        it('doesnt require a watermark', () => __awaiter(void 0, void 0, void 0, function* () {
            const alice = yield TestDataGenerator.generatePersona();
            const eventsGet = yield EventsGet.create({
                authorizationSignatureInput: yield Jws.createSignatureInput(alice)
            });
            const message = eventsGet.message;
            expect(message.descriptor).to.exist;
            expect(message.descriptor.watermark).to.not.exist;
            expect(message.authorization).to.exist;
        }));
    });
    describe('parse', () => {
        it('parses a message into an EventsGet instance', () => __awaiter(void 0, void 0, void 0, function* () {
            const alice = yield TestDataGenerator.generatePersona();
            const eventsGet = yield EventsGet.create({
                watermark: 'yolo',
                authorizationSignatureInput: yield Jws.createSignatureInput(alice)
            });
            const parsed = yield EventsGet.parse(eventsGet.message);
            expect(parsed).to.be.instanceof(EventsGet);
            const expectedMessageCid = yield Message.getCid(eventsGet.message);
            const messageCid = yield Message.getCid(parsed.message);
            expect(messageCid).to.equal(expectedMessageCid);
        }));
        it('throws an exception if message is not a valid EventsGet message', () => __awaiter(void 0, void 0, void 0, function* () {
            const alice = yield TestDataGenerator.generatePersona();
            const eventsGet = yield EventsGet.create({
                watermark: 'yolo',
                authorizationSignatureInput: yield Jws.createSignatureInput(alice)
            });
            const { message } = eventsGet;
            message['hehe'] = 'troll';
            try {
                yield EventsGet.parse(message);
                expect.fail();
            }
            catch (e) {
                expect(e.message).to.include('additional properties');
            }
        }));
    });
});
//# sourceMappingURL=events-get.spec.js.map