import { PR_WATCH } from 'bitbucket/internal/bbui/actions/pull-request';
import pullRequestWatch from 'bitbucket/internal/bbui/reducers/pull-request-watch';

QUnit.module('pull-request-watch');

QUnit.test('it can switch watch state', function(assert) {
    const newState = pullRequestWatch(false, {
        type: PR_WATCH,
        payload: true,
        meta: {
            isPending: true,
        },
    });
    assert.deepEqual(newState, true);
});

QUnit.test('it will optimistically update', function(assert) {
    const newState = pullRequestWatch(false, {
        type: PR_WATCH,
        payload: true,
        meta: {
            isPending: true,
        },
    });
    assert.deepEqual(newState, true);
});

QUnit.test('it rolls back on failure', function(assert) {
    const newState = pullRequestWatch(false, {
        type: PR_WATCH,
        payload: {
            error: {
                status: 401,
                statusText: 'Unauthorized',
            },
        },
        meta: {
            isPending: false,
        },
    });
    assert.deepEqual(newState, false);
});
