import {
    LOAD_REPOSITORIES_SUCCESS,
} from 'bitbucket/internal/feature/dashboard/actions';
import repositoriesReducer from 'bitbucket/internal/feature/dashboard/reducers/repositories';

QUnit.module('dashboard-paging-reducer');

QUnit.test('it upserts repositories on LOAD_REPOSITORIES_SUCCESS', function (assert) {
    const originalRepo = {
        id: 1,
        foo: 'bar',
        dont: 'touch',
    };

    const newRepo = {
        id: 2,
        whatever: 'whenever'
    };

    const newState = repositoriesReducer({
        1: originalRepo
    }, {
        type: LOAD_REPOSITORIES_SUCCESS,
        payload: {
            values: [
                {
                    id: 1,
                    foo: 'baz',
                },
                newRepo,
            ]
        }
    });

    assert.equal(Object.keys(newState).length, 2);
    assert.deepEqual(newState, {
        1: {
            ...originalRepo,
            foo: 'baz',
        },
        2: newRepo,
    });
});