Skip to content

Commit

Permalink
feat: add unit tests for all cases of getUpdateFrequencyFromCustomPerio
Browse files Browse the repository at this point in the history
  • Loading branch information
cmoinier committed Nov 15, 2024
1 parent 2edb337 commit 41436c1
Showing 1 changed file with 49 additions and 3 deletions.
52 changes: 49 additions & 3 deletions libs/api/metadata-converter/src/lib/iso19139/read-parts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,61 @@ describe('read parts', () => {
})
})
describe('getUpdateFrequencyFromCustomPeriod', () => {
it('keeps a partial weekly period', () => {
expect(getUpdateFrequencyFromCustomPeriod('P0Y0M2D')).toEqual({
it('returns null for empty input', () => {
expect(getUpdateFrequencyFromCustomPeriod('')).toBeNull()
})
it('returns null for invalid input', () => {
expect(getUpdateFrequencyFromCustomPeriod('RSYZ45')).toBeNull()
})
it('handles yearly period', () => {
expect(getUpdateFrequencyFromCustomPeriod('P1Y')).toEqual({
updatedTimes: 1,
per: 'year',
})
})
it('handles monthly period of 1 month', () => {
expect(getUpdateFrequencyFromCustomPeriod('P1M')).toEqual({
updatedTimes: 1,
per: 'month',
})
})
it('handles monthly period of more than 1 month', () => {
expect(getUpdateFrequencyFromCustomPeriod('P3M')).toEqual({
updatedTimes: 4,
per: 'year',
})
})
it('handles daily period of 1 day', () => {
expect(getUpdateFrequencyFromCustomPeriod('P1D')).toEqual({
updatedTimes: 1,
per: 'day',
})
})
it('handles weekly period of 1 to 7 days', () => {
expect(getUpdateFrequencyFromCustomPeriod('P2D')).toEqual({
updatedTimes: 3,
per: 'week',
})
expect(getUpdateFrequencyFromCustomPeriod('P0Y0M3D')).toEqual({
expect(getUpdateFrequencyFromCustomPeriod('P3D')).toEqual({
updatedTimes: 2,
per: 'week',
})
expect(getUpdateFrequencyFromCustomPeriod('P7D')).toEqual({
updatedTimes: 1,
per: 'week',
})
})
it('handles monthly period of more than 7 days', () => {
expect(getUpdateFrequencyFromCustomPeriod('P10D')).toEqual({
updatedTimes: 3,
per: 'month',
})
})
it('handles hourly period', () => {
expect(getUpdateFrequencyFromCustomPeriod('PT6H')).toEqual({
updatedTimes: 4,
per: 'day',
})
})
})
})
Expand Down

0 comments on commit 41436c1

Please sign in to comment.