Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Editor]: Bug - Update frequency not kept #1041

Merged
merged 2 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading