import u from 'updeep';

import { Updux } from './Updux';

test('basic reducer', () => {
    const dux = new Updux({});

    expect(typeof dux.reducer).toBe('function');

    expect(dux.reducer({ a: 1 }, { type: 'foo' })).toMatchObject({ a: 1 }); // noop
});

test('basic upreducer', () => {
    const dux = new Updux({});

    expect(typeof dux.upreducer).toBe('function');

    expect(dux.upreducer({ type: 'foo' })({ a: 1 })).toMatchObject({ a: 1 }); // noop
});

test('reducer with action', () => {
    const dux = new Updux({
        actions: {
            inc: null,
        },
        mutations: {
            inc: () => u({ a: (x) => x + 1 }),
        },
    });

    expect(dux.reducer({ a: 1 }, { type: 'inc' })).toMatchObject({ a: 2 });
});
