<commit_before>import {
  IdentityActions, IdentityReducer
} from '../../../../app/js/profiles/store/identity'

const initialState = {
  current: {
    domainName: null,
    profile: null,
    verifications: null
  },
  localIdentities: {},
  namesOwned: [],
  createProfileError: null
}

const DEFAULT_PROFILE = {
  '@type': 'Person',
  '@context': 'http://schema.org'
}

describe('Identity Store: IdentityReducer', () => {
  it('should return the proper initial state', () => {
    assert.deepEqual(
      IdentityReducer(undefined, {}),
      initialState)
  })

  it('should update the current identity with the proper values', () => {
    const profile = {
      key: 'value'
    }
    const verifications = {
      verified: true
    }
    const action = IdentityActions.updateCurrentIdentity('satoshi.id', profile, verifications)
    const expectedState = {
      current: {
        domainName: 'satoshi.id',
        profile: { key: 'value' },
        verifications: { verified: true }
      },
      localIdentities: {},
      namesOwned: [],
      createProfileError: null
    }
    const actualState = IdentityReducer(undefined, action)
    assert.deepEqual(actualState, expectedState)
  })

  it('should create a new identity that is unregistered & unverified', () => {
    const action = IdentityActions.createNewIdentity('satoshi.id', '17jxDTPDx51CTga1Sw3ezGQKYcJysPNeQC')
    const expectedState = {
      current: {
        domainName: null,
        profile: null,
        verifications: null
      },
      localIdentities: {
        'satoshi.id': {
          domainName: 'satoshi.id',
          profile: DEFAULT_PROFILE,
          verifications: [],
          registered: false,
          ownerAddress: '17jxDTPDx51CTga1Sw3ezGQKYcJysPNeQC'
        }
      },
      namesOwned: [],
      createProfileError: null
    }
    const actualState = IdentityReducer(undefined, action)
    assert.deepEqual(actualState, expectedState)
  })

  it('should update the collection of local identites and list of names owned', () => {
    const namesOwned = ['satoshi.id']
    const localIdentities = {
      'satoshi.id': {
        domainName: 'satoshi.id',
        profile: DEFAULT_PROFILE,
        verifications: [],
        registered: false
      }
    }
    const action = IdentityActions.updateOwnedIdentities(localIdentities, namesOwned)
    const expectedState = {
      current: {
        domainName: null,
        profile: null,
        verifications: null
      },
      localIdentities: {
        'satoshi.id': {
          domainName: 'satoshi.id',
          profile: DEFAULT_PROFILE,
          verifications: [],
          registered: false
        }
      },
      namesOwned: ['satoshi.id'],
      createProfileError: null
    }
    const actualState = IdentityReducer(undefined, action)
    assert.deepEqual(actualState, expectedState)
  })

  it('should update the profile of the specified name', () => {
    const profile = {
      key: 'value'
    }
    const action = IdentityActions.updateProfile('satoshi.id', profile)
    const expectedState = {
      current: {
        domainName: null,
        profile: null,
        verifications: null
      },
      localIdentities: {
        'satoshi.id': {
          profile: {
            key: 'value'
          }
        }
      },
      namesOwned: [],
      createProfileError: null
    }
    const actualState = IdentityReducer(undefined, action)
    assert.deepEqual(actualState, expectedState)
  })

  it('should move the identity from owner address key to domain key', () => {
    const initialState = {
      localIdentities: {
        '<KEY>': {
          profile: {
            key: 'value'
          },
          ownerAddress: '17jxDTPDx51CTga1Sw3ezGQKYcJysPNeQC'
        }
      },
      createProfileError: null
    }

    const expectedState = {
      localIdentities: {
        'satoshi.id': {
          profile: {
            key: 'value'
          },
          ownerAddress: '17jxDTPDx51CTga1Sw3ezGQKYcJysPNeQC',
          domainName: 'satoshi.id'
        }
      },
      createProfileError: null
    }
    const action = IdentityActions.addUsername('satoshi.id', '17jxDTPDx51CTga1Sw3ezGQKYcJysPNeQC')

    const actualState = IdentityReducer(initialState, action)
    assert.deepEqual(actualState, expectedState)
  })

  it('should create a create new profile error', () => {
    const expectedState = {
      current: {
        domainName: null,
        profile: null,
        verifications: null
      },
      localIdentities: {},
      namesOwned: [],
      createProfileError: 'error'
    }
    const action = IdentityActions.createNewProfileError('error')

    const actualState = IdentityReducer(initialState, action)
    assert.deepEqual(actualState, expectedState)
  })
})<commit_msg>Fix tests<commit_after>import {
  IdentityActions, IdentityReducer
} from '../../../../app/js/profiles/store/identity'

const initialState = {
  default: null,
  current: {
    domainName: null,
    profile: null,
    verifications: null
  },
  localIdentities: {},
  namesOwned: [],
  createProfileError: null
}

const DEFAULT_PROFILE = {
  '@type': 'Person',
  '@context': 'http://schema.org'
}

describe('Identity Store: IdentityReducer', () => {
  it('should return the proper initial state', () => {
    assert.deepEqual(
      IdentityReducer(undefined, {}),
      initialState)
  })

  it('should update the current identity with the proper values', () => {
    const profile = {
      key: 'value'
    }
    const verifications = {
      verified: true
    }
    const action = IdentityActions.updateCurrentIdentity('satoshi.id', profile, verifications)
    const expectedState = {
      default: null,
      current: {
        domainName: 'satoshi.id',
        profile: { key: 'value' },
        verifications: { verified: true }
      },
      localIdentities: {},
      namesOwned: [],
      createProfileError: null
    }
    const actualState = IdentityReducer(undefined, action)
    assert.deepEqual(actualState, expectedState)
  })

  it('should create a new identity that is unregistered & unverified', () => {
    const action = IdentityActions.createNewIdentity('satoshi.id', '17jxDTPDx51CTga1Sw3ezGQKYcJysPNeQC')
    const expectedState = {
      default: null,
      current: {
        domainName: null,
        profile: null,
        verifications: null
      },
      localIdentities: {
        'satoshi.id': {
          domainName: 'satoshi.id',
          profile: DEFAULT_PROFILE,
          verifications: [],
          registered: false,
          ownerAddress: '17jxDTPDx51CTga1Sw3ezGQKYcJysPNeQC'
        }
      },
      namesOwned: [],
      createProfileError: null
    }
    const actualState = IdentityReducer(undefined, action)
    assert.deepEqual(actualState, expectedState)
  })

  it('should set the default identity', () => {
    const action = IdentityActions.setDefaultIdentity('satoshi.id')
    const expectedState = {
      default: 'satoshi.id',
      current: {
        domainName: null,
        profile: null,
        verifications: null
      },
      localIdentities: {},
      namesOwned: [],
      createProfileError: null
    }
    const actualState = IdentityReducer(undefined, action)
    assert.deepEqual(actualState, expectedState)
  })

  it('should update the collection of local identites and list of names owned', () => {
    const namesOwned = ['satoshi.id']
    const localIdentities = {
      'satoshi.id': {
        domainName: 'satoshi.id',
        profile: DEFAULT_PROFILE,
        verifications: [],
        registered: false
      }
    }
    const action = IdentityActions.updateOwnedIdentities(localIdentities, namesOwned)
    const expectedState = {
      default: null,
      current: {
        domainName: null,
        profile: null,
        verifications: null
      },
      localIdentities: {
        'satoshi.id': {
          domainName: 'satoshi.id',
          profile: DEFAULT_PROFILE,
          verifications: [],
          registered: false
        }
      },
      namesOwned: ['satoshi.id'],
      createProfileError: null
    }
    const actualState = IdentityReducer(undefined, action)
    assert.deepEqual(actualState, expectedState)
  })

  it('should update the profile of the specified name', () => {
    const profile = {
      key: 'value'
    }
    const action = IdentityActions.updateProfile('satoshi.id', profile)
    const expectedState = {
      default: null,
      current: {
        domainName: null,
        profile: null,
        verifications: null
      },
      localIdentities: {
        'satoshi.id': {
          profile: {
            key: 'value'
          }
        }
      },
      namesOwned: [],
      createProfileError: null
    }
    const actualState = IdentityReducer(undefined, action)
    assert.deepEqual(actualState, expectedState)
  })

  it('should update the profile of the specified name', () => {
    const profile = {
      key: 'value'
    }
    const action = IdentityActions.updateProfile('satoshi.id', profile)
    const expectedState = {
      default: null,
      current: {
        domainName: null,
        profile: null,
        verifications: null
      },
      localIdentities: {
        'satoshi.id': {
          profile: {
            key: 'value'
          }
        }
      },
      namesOwned: [],
      createProfileError: null
    }
    const actualState = IdentityReducer(undefined, action)
    assert.deepEqual(actualState, expectedState)
  })

  it('should move the identity from owner address key to domain key', () => {
    const initialState = {
      localIdentities: {
        '17jxDTPDx51CTga1Sw3ezGQKYcJysPNeQC': {
          profile: {
            key: 'value'
          },
          ownerAddress: '17jxDTPDx51CTga1Sw3ezGQKYcJysPNeQC'
        }
      },
      createProfileError: null
    }

    const expectedState = {
      localIdentities: {
        'satoshi.id': {
          profile: {
            key: 'value'
          },
          ownerAddress: '17jxDTPDx51CTga1Sw3ezGQKYcJysPNeQC',
          domainName: 'satoshi.id'
        }
      },
      createProfileError: null
    }
    const action = IdentityActions.addUsername('satoshi.id', '17jxDTPDx51CTga1Sw3ezGQKYcJysPNeQC')

    const actualState = IdentityReducer(initialState, action)
    assert.deepEqual(actualState, expectedState)
  })

  it('should create a create new profile error', () => {
    const expectedState = {
      default: null,
      current: {
        domainName: null,
        profile: null,
        verifications: null
      },
      localIdentities: {},
      namesOwned: [],
      createProfileError: 'error'
    }
    const action = IdentityActions.createNewProfileError('error')

    const actualState = IdentityReducer(initialState, action)
    assert.deepEqual(actualState, expectedState)
  })
})
{'fraction_non_alphanumeric': 0.11001201811962652, 'fraction_numerical': 0.0061015068873070165, 'mean_word_length': 2.3617153511497824, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 22, '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': '969227', 'n_tokens_mistral': 3238, 'n_tokens_neox': 3122, 'n_words': 665}