Skip to content

Commit

Permalink
Merge pull request #1041 from geonetwork/ME-frequency-not-kept-bug
Browse files Browse the repository at this point in the history
[Editor]: Bug - Update frequency not kept
  • Loading branch information
cmoinier authored Nov 18, 2024
2 parents 1aab0c3 + 9db51f0 commit 68624e7
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
48 changes: 47 additions & 1 deletion libs/api/metadata-converter/src/lib/iso19139/read-parts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,37 @@ describe('read parts', () => {
})
})
describe('getUpdateFrequencyFromCustomPeriod', () => {
it('keeps a partial weekly period', () => {
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('P0Y1M')).toEqual({
updatedTimes: 1,
per: 'month',
})
})
it('handles monthly period of more than 1 month', () => {
expect(getUpdateFrequencyFromCustomPeriod('P0Y3M')).toEqual({
updatedTimes: 4,
per: 'year',
})
})
it('handles daily period of 1 day', () => {
expect(getUpdateFrequencyFromCustomPeriod('P0Y0M1D')).toEqual({
updatedTimes: 1,
per: 'day',
})
})
it('handles weekly period of 1 to 7 days', () => {
expect(getUpdateFrequencyFromCustomPeriod('P0Y0M2D')).toEqual({
updatedTimes: 3,
per: 'week',
Expand All @@ -122,6 +152,22 @@ describe('read parts', () => {
updatedTimes: 2,
per: 'week',
})
expect(getUpdateFrequencyFromCustomPeriod('P0Y0M7D')).toEqual({
updatedTimes: 1,
per: 'week',
})
})
it('handles monthly period of more than 7 days', () => {
expect(getUpdateFrequencyFromCustomPeriod('P0Y0M10D')).toEqual({
updatedTimes: 3,
per: 'month',
})
})
it('handles hourly period', () => {
expect(getUpdateFrequencyFromCustomPeriod('P0Y0M0DT6H')).toEqual({
updatedTimes: 4,
per: 'day',
})
})
})
})
Expand Down
4 changes: 2 additions & 2 deletions libs/api/metadata-converter/src/lib/iso19139/read-parts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ export function getUpdateFrequencyFromCustomPeriod(
per: 'day',
updatedTimes: 1,
}
} else if (days <= 7) {
} else if (days >= 1 && days <= 7) {
return {
per: 'week',
updatedTimes: Math.round(7 / days - 0.0001), // this is to make sure that 'every 2 days' = '3 times per week'
Expand All @@ -553,7 +553,7 @@ export function getUpdateFrequencyFromCustomPeriod(
} else if (hours) {
return {
per: 'day',
updatedTimes: Math.round(24 / days),
updatedTimes: Math.round(24 / hours),
}
}
return null
Expand Down

0 comments on commit 68624e7

Please sign in to comment.