import * as tslib_1 from "tslib";
import { addActionMiddleware, addGetterMiddleware, addMutationMiddleware, addStateMiddleware } from '../../../src/StoreModule/middlewares';
import { Action, Getter, Mutation, State } from '../../../src/StoreModule/annotations';
import { expect } from 'chai';
import { StoreModule } from '../../../src/StoreModule/StoreModule';
import { Api } from './Api';
describe('store middlewares tests', () => {
    const mutOptVal = 'mutOptVal', getOptVal = 'getOptVal', actOptVal = 'actOptVal', statOptVal = 'statOptVal';
    it('should add middlewares and run it with correct params in annotation function', async () => {
        const promise = Promise.all([
            new Promise(resolve => {
                addMutationMiddleware((options, target, propertyKey, descriptor) => {
                    expect(options).is.not.undefined;
                    expect(options.mutOpt).equals(mutOptVal);
                }, (options, target, propertyKey, descriptor) => {
                    expect(options).exist;
                    expect(target).exist;
                    expect(propertyKey).exist;
                    expect(descriptor).exist;
                    resolve();
                });
            }),
            new Promise(resolve => {
                addGetterMiddleware((options, target, propertyKey, descriptor) => {
                    expect(options).is.not.undefined;
                    expect(options.getOpt).equals(getOptVal);
                }, (options, target, propertyKey, descriptor) => {
                    expect(options).exist;
                    expect(target).exist;
                    expect(propertyKey).exist;
                    expect(descriptor).exist;
                    resolve();
                });
            }),
            new Promise(resolve => {
                addActionMiddleware((options, target, propertyKey, descriptor) => {
                    expect(options).is.not.undefined;
                    expect(options.actOpt).equals(actOptVal);
                }, (options, target, propertyKey, descriptor) => {
                    expect(options).exist;
                    expect(target).exist;
                    expect(propertyKey).exist;
                    expect(descriptor).exist;
                    resolve();
                });
            }),
            new Promise(resolve => {
                addStateMiddleware((options, target, propertyKey) => {
                    expect(options).is.not.undefined;
                    expect(options.statOpt).equals(statOptVal);
                }, (options, target, propertyKey) => {
                    expect(options).exist;
                    expect(target).exist;
                    expect(propertyKey).exist;
                    resolve();
                });
            })
        ]);
        class TestRepository extends StoreModule {
            setSomeState(some) {
                this.someState = some;
            }
            async updateSomeState() {
                await Api.send();
                this.setSomeState('bla');
            }
            get computedSomeState() {
                return 'comp' + this.someState;
            }
        }
        tslib_1.__decorate([
            State({ statOpt: statOptVal })
        ], TestRepository.prototype, "someState", void 0);
        tslib_1.__decorate([
            Mutation({ mutOpt: mutOptVal })
        ], TestRepository.prototype, "setSomeState", null);
        tslib_1.__decorate([
            Action({ actOpt: actOptVal })
        ], TestRepository.prototype, "updateSomeState", null);
        tslib_1.__decorate([
            Getter({ getOpt: getOptVal })
        ], TestRepository.prototype, "computedSomeState", null);
        new TestRepository();
        await promise;
    });
});
//# sourceMappingURL=middlewares.spec.js.map