<commit_before>import { expect } from 'chai'
import Immutable, { Map } from 'immutable'
import { start, success, error } from '../../src/reducers/update'

describe('Reducers::Update', () => {
  describe('start', () => {
    it('should update data in state and store previous version in pendingUpdate', () => {
      const previousState = Map({
        raw: Map([[123, Immutable.fromJS({ uid: 123, test: '123' })]]),
        pendingUpdate: Map({})
      })

      const action = {
        record: Immutable.fromJS({ uid: 123, test: 'name' }),
        uidField: 'uid'
      }

      const expectedResult = {
        raw: {
          123: { uid: 123, test: 'name' }
        },
        pendingUpdate: {
          123: { uid: 123, test: '123' }
        }
      }

      expect(start(previousState, action).toJS()).to.deep.equal(expectedResult)
    })
  })

  describe('success', () => {
    it('should remove the previous version from pendingUpdate', () => {<commit_msg>add test: update reducer should merge partial changes with existing data<commit_after>import { expect } from 'chai'
import Immutable, { Map } from 'immutable'
import { start, success, error } from '../../src/reducers/update'

describe('Reducers::Update', () => {
  describe('start', () => {
    it('should update data in state and store previous version in pendingUpdate', () => {
      const previousState = Map({
        raw: Map([[123, Immutable.fromJS({ uid: 123, test: '123' })]]),
        pendingUpdate: Map({})
      })

      const action = {
        record: Immutable.fromJS({ uid: 123, test: 'name' }),
        uidField: 'uid'
      }

      const expectedResult = {
        raw: {
          123: { uid: 123, test: 'name' }
        },
        pendingUpdate: {
          123: { uid: 123, test: '123' }
        }
      }

      expect(start(previousState, action).toJS()).to.deep.equal(expectedResult)
    })


    it('should merge partial changes with existing data', () => {
      const previousState = Map({
        raw: Map([[123, Immutable.fromJS({ uid: 123, test: '123', company: 'Acme' })]]),
        pendingUpdate: Map({})
      })

      const action = {
        record: Immutable.fromJS({ uid: 123, test: 'name' }),
        uidField: 'uid'
      }

      const expectedResult = {
        raw: {
          123: { uid: 123, test: 'name', company: 'Acme' }
        },
        pendingUpdate: {
          123: { uid: 123, test: '123', company: 'Acme' }
        }
      }

      expect(start(previousState, action).toJS()).to.deep.equal(expectedResult)
    })

  })

  describe('success', () => {
    it('should remove the previous version from pendingUpdate', () => {
{'fraction_non_alphanumeric': 0.16483931947069944, 'fraction_numerical': 0.03062381852551985, 'mean_word_length': 2.375, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4518669', 'n_tokens_mistral': 864, 'n_tokens_neox': 786, 'n_words': 209}