import { createStore } from '~/tests/unit/Helpers'
import { $organizationProfile } from '~/services/profile/organizationProfile'
import { organizationProfile as organizationModule } from '~/tests/unit/fixture/state/profile'
import { OrganizationStore } from '~/types/interfaces'
let store:OrganizationStore, organizationProfile:any

beforeAll(() => {
  process.env = {
    school_product: 'school',
    school_premium_product: 'school-premium',
    artist_product: 'artist',
    artist_premium_product: 'artist-premium',
    manager_product: 'manager',
    cmf_network: 'CMF',
    ffec_network: 'FFEC'
  }
})

beforeEach(() => {
  store = createStore()
  store.registerModule('profile', {})
  store.registerModule(['profile', 'organization'], organizationModule)
  organizationProfile = $organizationProfile(store)
})

describe('hasModule()', () => {
  it('should return false if organization dont have one of the module', () => {
    expect(organizationProfile.hasModule(['PedagogicsAdministation'])).toBeFalsy()
  })

  it('should return true if organization have one of the module', () => {
    store.commit('organization/setModules', ['PedagogicsAdministation', 'Courses'])
    expect(organizationProfile.hasModule(['PedagogicsAdministation', 'Examens'])).toBeTruthy()
  })
})

describe('isInsideNetwork()', () => {
  it('should call isCmf function', () => {
    organizationProfile.isCmf = jest.fn()
    organizationProfile.isInsideNetwork()
    expect(organizationProfile.isCmf).toHaveBeenCalled()
  })
  it('should call isFfec function if isCmf return false', () => {
    organizationProfile.isCmf = jest.fn().mockReturnValue(false)
    organizationProfile.isFfec = jest.fn()
    organizationProfile.isInsideNetwork()
    expect(organizationProfile.isFfec).toHaveBeenCalled()
  })
  it('should return false if isCmf AND isFfec return false', () => {
    organizationProfile.isCmf = jest.fn().mockReturnValue(false)
    organizationProfile.isFfec = jest.fn().mockReturnValue(false)
    expect(organizationProfile.isInsideNetwork()).toBeFalsy()
  })
  it('should return true if isCmf OR Ffec return true', () => {
    organizationProfile.isCmf = jest.fn().mockReturnValue(true)
    expect(organizationProfile.isInsideNetwork()).toBeTruthy()

    organizationProfile.isCmf = jest.fn().mockReturnValue(false)
    organizationProfile.isFfec = jest.fn().mockReturnValue(true)
    expect(organizationProfile.isInsideNetwork()).toBeTruthy()
  })
})

describe('isCmf()', () => {
  it('should return false if the organization is not CMF', () => {
    expect(organizationProfile.isCmf()).toBeFalsy()
  })
  it('should return true if the organization is not CMF', () => {
    store.commit('organization/setNetworks', ['CMF'])
    expect(organizationProfile.isCmf()).toBeTruthy()
  })
})

describe('isFfec()', () => {
  it('should return false if the organization is not FFEC', () => {
    expect(organizationProfile.isFfec()).toBeFalsy()
  })
  it('should return true if the organization is not FFEC', () => {
    store.commit('organization/setNetworks', ['FFEC'])
    expect(organizationProfile.isFfec()).toBeTruthy()
  })
})

describe('isSchool()', () => {
  it('should call isSchoolProduct function', () => {
    organizationProfile.isSchoolProduct = jest.fn()
    organizationProfile.isSchool()
    expect(organizationProfile.isSchoolProduct).toHaveBeenCalled()
  })
  it('should call isSchoolPremiumProduct function if isSchool return false', () => {
    organizationProfile.isSchoolProduct = jest.fn().mockReturnValue(false)
    organizationProfile.isSchoolPremiumProduct = jest.fn()
    organizationProfile.isSchool()
    expect(organizationProfile.isSchoolPremiumProduct).toHaveBeenCalled()
  })
  it('should return false if isSchoolProduct AND isSchoolPremiumProduct return false', () => {
    organizationProfile.isSchoolProduct = jest.fn().mockReturnValue(false)
    organizationProfile.isSchoolPremiumProduct = jest.fn().mockReturnValue(false)
    expect(organizationProfile.isSchool()).toBeFalsy()
  })
  it('should return true if isSchoolProduct OR isSchoolPremiumProduct return true', () => {
    organizationProfile.isSchoolProduct = jest.fn().mockReturnValue(true)
    expect(organizationProfile.isSchool()).toBeTruthy()

    organizationProfile.isSchoolProduct = jest.fn().mockReturnValue(false)
    organizationProfile.isSchoolPremiumProduct = jest.fn().mockReturnValue(true)
    expect(organizationProfile.isSchool()).toBeTruthy()
  })
})

describe('isArtist()', () => {
  it('should call isArtistProduct function', () => {
    organizationProfile.isArtistProduct = jest.fn()
    organizationProfile.isArtist()
    expect(organizationProfile.isArtistProduct).toHaveBeenCalled()
  })
  it('should call isArtistPremiumProduct function if isArtistProduct return false', () => {
    organizationProfile.isArtistProduct = jest.fn().mockReturnValue(false)
    organizationProfile.isArtistPremiumProduct = jest.fn()
    organizationProfile.isArtist()
    expect(organizationProfile.isArtistPremiumProduct).toHaveBeenCalled()
  })
  it('should return false if isArtistProduct AND isArtistPremiumProduct return false', () => {
    organizationProfile.isArtistProduct = jest.fn().mockReturnValue(false)
    organizationProfile.isArtistPremiumProduct = jest.fn().mockReturnValue(false)
    expect(organizationProfile.isArtist()).toBeFalsy()
  })
  it('should return true if isArtistProduct OR isArtistPremiumProduct return true', () => {
    organizationProfile.isArtistProduct = jest.fn().mockReturnValue(true)
    expect(organizationProfile.isArtist()).toBeTruthy()

    organizationProfile.isArtistProduct = jest.fn().mockReturnValue(false)
    organizationProfile.isArtistPremiumProduct = jest.fn().mockReturnValue(true)
    expect(organizationProfile.isArtist()).toBeTruthy()
  })
})

describe('isSchoolProduct()', () => {
  it('should return false if the organization dont have a shool product', () => {
    expect(organizationProfile.isSchoolProduct()).toBeFalsy()
  })

  it('should return true if the organization have a shool product', () => {
    store.commit('organization/setProduct', 'school')
    expect(organizationProfile.isSchoolProduct()).toBeTruthy()
  })
})

describe('isSchoolPremiumProduct()', () => {
  it('should return false if the organization dont have a shool premium product', () => {
    expect(organizationProfile.isSchoolPremiumProduct()).toBeFalsy()
  })

  it('should return true if the organization have a shool premium product', () => {
    store.commit('organization/setProduct', 'school-premium')
    expect(organizationProfile.isSchoolPremiumProduct()).toBeTruthy()
  })
})

describe('isArtistProduct()', () => {
  it('should return false if the organization dont have a artist product', () => {
    expect(organizationProfile.isArtistProduct()).toBeFalsy()
  })

  it('should return true if the organization have a artist product', () => {
    store.commit('organization/setProduct', 'artist')
    expect(organizationProfile.isArtistProduct()).toBeTruthy()
  })
})

describe('isArtistPremiumProduct()', () => {
  it('should return false if the organization dont have a artist premium product', () => {
    expect(organizationProfile.isArtistPremiumProduct()).toBeFalsy()
  })

  it('should return true if the organization have a artist premium product', () => {
    store.commit('organization/setProduct', 'artist-premium')
    expect(organizationProfile.isArtistPremiumProduct()).toBeTruthy()
  })
})

describe('isManagerProduct()', () => {
  it('should return false if the organization dont have a manager product', () => {
    expect(organizationProfile.isManagerProduct()).toBeFalsy()
  })

  it('should return true if the organization have a manager product', () => {
    store.commit('organization/setProduct', 'manager')
    expect(organizationProfile.isManagerProduct()).toBeTruthy()
  })
})

describe('isOrganizationWithChildren()', () => {
  it('should return false if the organization dont have children', () => {
    expect(organizationProfile.hasChildren()).toBeFalsy()
  })

  it('should return true if the organization have children', () => {
    store.commit('organization/setHasChildren', true)
    expect(organizationProfile.hasChildren()).toBeTruthy()
  })
})
