Skip to content
Snippets Groups Projects
Commit ad206f36 authored by Bastien DUMONT's avatar Bastien DUMONT :angel:
Browse files

Merge branch 'coverage' into 'dev'

test: improve coverage

See merge request !929
parents 42d52c30 ca2fbed9
No related branches found
No related tags found
2 merge requests!9322.5,!929test: improve coverage
import { Season } from 'enum/ecogesture.enum'
import { FluidType } from 'enum/fluid.enum'
import { FluidState, FluidType } from 'enum/fluid.enum'
import { FluidSlugType } from 'enum/fluidSlug.enum'
import { KonnectorUpdate } from 'enum/konnectorUpdate.enum'
import { DateTime } from 'luxon'
import { FluidStatus } from 'models'
import {
formatNumberValues,
getChallengeTitleWithLineReturn,
getFluidType,
getKonnectorSlug,
getKonnectorUpdateError,
getMonthFullName,
getMonthName,
getMonthNameWithPrep,
getSeason,
isKonnectorActive,
} from './utils'
describe('utils test', () => {
......@@ -42,6 +48,80 @@ describe('utils test', () => {
expect(slug).toBe(FluidSlugType.GAS)
})
})
describe('getKonnectorUpdateError', () => {
it('should return KonnectorUpdate.ERROR_UPDATE_OAUTH for USER_ACTION_NEEDED.OAUTH_OUTDATED', () => {
const result = getKonnectorUpdateError(
'USER_ACTION_NEEDED.OAUTH_OUTDATED'
)
expect(result).toBe(KonnectorUpdate.ERROR_UPDATE_OAUTH)
})
it('should return KonnectorUpdate.LOGIN_FAILED for LOGIN_FAILED', () => {
const result = getKonnectorUpdateError('LOGIN_FAILED')
expect(result).toBe(KonnectorUpdate.LOGIN_FAILED)
})
it('should return KonnectorUpdate.ERROR_CONSENT_FORM_GAS for CHALLENGE_ASKED', () => {
const result = getKonnectorUpdateError('CHALLENGE_ASKED')
expect(result).toBe(KonnectorUpdate.ERROR_CONSENT_FORM_GAS)
})
it('should return KonnectorUpdate.ERROR_UPDATE for an unknown type', () => {
const result = getKonnectorUpdateError('UNKNOWN_TYPE')
expect(result).toBe(KonnectorUpdate.ERROR_UPDATE)
})
})
describe('isKonnectorActive', () => {
describe('for MULTIFLUID', () => {
it('should return false when all fluids are not connected', () => {
const fluidStatus = [
{ status: FluidState.NOT_CONNECTED },
{ status: FluidState.KONNECTOR_NOT_FOUND },
{ status: FluidState.NOT_CONNECTED },
] as FluidStatus[]
const result = isKonnectorActive(fluidStatus, FluidType.MULTIFLUID)
expect(result).toBe(false)
})
it('should return true when some fluids are connected', () => {
const fluidStatus = [
{ status: FluidState.DONE },
{ status: FluidState.NOT_CONNECTED },
{ status: FluidState.DONE },
] as FluidStatus[]
const result = isKonnectorActive(fluidStatus, FluidType.MULTIFLUID)
expect(result).toBe(true)
})
})
describe('for SINGLE fluids', () => {
it('should return false for a single fluid not connected', () => {
const fluidStatus = [
{},
{
status: FluidState.NOT_CONNECTED,
fluidType: FluidType.GAS,
},
{
status: FluidState.KONNECTOR_NOT_FOUND,
fluidType: FluidType.WATER,
},
] as FluidStatus[]
expect(isKonnectorActive(fluidStatus, FluidType.GAS)).toBe(false)
expect(isKonnectorActive(fluidStatus, FluidType.WATER)).toBe(false)
})
it('should return true for a single fluid connected', () => {
const fluidStatus = [
{
status: FluidState.DONE,
fluidType: FluidType.ELECTRICITY,
},
{ status: FluidState.ERROR, fluidType: FluidType.WATER },
{ status: FluidState.ERROR_LOGIN_FAILED, fluidType: FluidType.GAS },
] as FluidStatus[]
expect(isKonnectorActive(fluidStatus, FluidType.ELECTRICITY)).toBe(true)
expect(isKonnectorActive(fluidStatus, FluidType.GAS)).toBe(true)
expect(isKonnectorActive(fluidStatus, FluidType.WATER)).toBe(true)
})
})
})
describe('formatNumberValues test', () => {
it('should return --,-- if there is not value', () => {
......@@ -105,6 +185,18 @@ describe('utils test', () => {
expect(getChallengeTitleWithLineReturn('CHALLENGE0000')).toBe(undefined)
})
})
describe('getMonthFullName', () => {
it('should return the name of the month', () => {
expect(getMonthFullName(3)).toBe('Mars')
})
})
describe('getMonthFullName', () => {
it('should return the name of the month', () => {
expect(getMonthName(DateTime.local(2023, 6, 1))).toBe('juin')
})
})
describe('getMonthNameWithPrep', () => {
it('should return the name of the month with " de " ', () => {
const date = DateTime.fromISO('2020-11-29T23:59:59.999Z')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment