Newer
Older
import { Season } from 'enum/ecogesture.enum'
import { FluidState, FluidType } from 'enum/fluid.enum'
import { FluidSlugType } from 'enum/fluidSlug.enum'
import { KonnectorUpdate } from 'enum/konnectorUpdate.enum'
import {
formatNumberValues,
getChallengeTitleWithLineReturn,
getFluidType,
getKonnectorUpdateError,
getMonthFullName,
getMonthName,
getMonthNameWithPrep,
describe('utils test', () => {
it('should the electricity fluid type', () => {
const result = getFluidType('eLectRicity')
expect(result).toBe(FluidType.ELECTRICITY)
})
it('should the water fluid type', () => {
const result = getFluidType('WatER')
expect(result).toBe(FluidType.WATER)
})
it('should the gas fluid type', () => {
const result = getFluidType('gas')
expect(result).toBe(FluidType.GAS)
})
})
describe('getKonnectorSlug', () => {
it('should return correct slug for elec', () => {
const slug = getKonnectorSlug(FluidType.ELECTRICITY)
expect(slug).toBe(FluidSlugType.ELECTRICITY)
})
it('should return correct slug for water', () => {
const slug = getKonnectorSlug(FluidType.WATER)
expect(slug).toBe(FluidSlugType.WATER)
})
it('should return correct slug for gas', () => {
const slug = getKonnectorSlug(FluidType.GAS)
expect(slug).toBe(FluidSlugType.GAS)
})
})
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
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)
})
})
})
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
describe('formatNumberValues test', () => {
it('should return --,-- if there is not value', () => {
const result = formatNumberValues(null)
expect(result).toBe('--,--')
})
it('should return a value at english number format two digits decimal', () => {
const result = formatNumberValues(2000.555)
expect(result).toEqual('2 000,56')
})
it('should return a float value', () => {
const result = formatNumberValues(2000.55, '', true)
expect(result).toEqual(2000)
})
})
describe('getSeason test', () => {
it('should return summer', () => {
const now = DateTime.local().setZone('utc', {
keepLocalTime: true,
})
jest
.spyOn(DateTime, 'local')
.mockReturnValueOnce(now.set({ day: 12, month: 6, year: 2021 }))
const result = getSeason()
expect(result).toBe(Season.SUMMER)
})
it('should return winter', () => {
const now = DateTime.local().setZone('utc', {
keepLocalTime: true,
})
jest
.spyOn(DateTime, 'local')
.mockReturnValueOnce(now.set({ day: 1, month: 12, year: 2021 }))
const result = getSeason()
expect(result).toBe(Season.WINTER)
})
it('should return none', () => {
const now = DateTime.local().setZone('utc', {
keepLocalTime: true,
})
jest
.spyOn(DateTime, 'local')
.mockReturnValueOnce(now.set({ day: 1, month: 10, year: 2021 }))
const result = getSeason()
expect(result).toBe(Season.NONE)
})
})
describe('getChallengeTitleWithLineReturn test', () => {
it('should return Simone\\nVEILLE', () => {
expect(getChallengeTitleWithLineReturn('CHALLENGE0001')).toBe(
'Simone\nVEILLE'
)
})
it('should return undefined', () => {
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')
expect(getMonthNameWithPrep(date)).toBe('de novembre')
})
it('should return the name of the month with " d\'" ', () => {
const date = DateTime.fromISO('2020-10-29T23:59:59.999Z')
expect(getMonthNameWithPrep(date)).toBe('d’octobre')
})
})