diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..fb4cd16 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,5 @@ +{ + "tasks": { + "test": "npm install && npm test" + } +} \ No newline at end of file diff --git a/src/sportlink-to-mailchimp-converter.ts b/src/sportlink-to-mailchimp-converter.ts index e703447..59bd7ec 100644 --- a/src/sportlink-to-mailchimp-converter.ts +++ b/src/sportlink-to-mailchimp-converter.ts @@ -76,7 +76,7 @@ const sportlinkRowToContact = (row: SportlinkRow, config: SportlinkToMailchimpCo } // If not tagged yet, assume Athletics - if (tags.length === 0) { + if (tags.length === 0 && categorie !== null && categorie !== undefined) { tags.push(`Atletiek ${stripGender(categorie)}`) } @@ -141,4 +141,4 @@ const parseCsv = async (file: LocalFile) => new Promise((resolve const formatParseErrors = (errors: ParseError[]): string => errors .map(error => `type: ${error.type}, code: ${error.code}, message: ${error.message}, row: ${error.row}, index: ${error.index}`) - .join('\n') \ No newline at end of file + .join('\n') diff --git a/src/string-utilities.test.ts b/src/string-utilities.test.ts index 915f28f..3a75f7c 100644 --- a/src/string-utilities.test.ts +++ b/src/string-utilities.test.ts @@ -1,37 +1,42 @@ -import { stripGender, isNullOrEmpty, trimSpacesAndRemoveDoubleQuotes } from './string-utilities' - -describe('stripGender', () => { - it('should remove gender-related words and trim the string', () => { - expect(stripGender('Meisjes kleding')).toBe('kleding') - expect(stripGender('Jongens schoenen')).toBe('schoenen') - expect(stripGender('Vrouwen accessoires')).toBe('accessoires') - expect(stripGender('Mannen horloges')).toBe('horloges') - expect(stripGender('Unisex kleding')).toBe('Unisex kleding') // No gender-related word - }) -}) - -describe('isNullOrEmpty', () => { - it('should return true for undefined, null, or empty strings', () => { - expect(isNullOrEmpty(undefined!)).toBe(true) - expect(isNullOrEmpty(null!)).toBe(true) - expect(isNullOrEmpty('')).toBe(true) - }) - - it('should return false for non-empty strings', () => { - expect(isNullOrEmpty('text')).toBe(false) - expect(isNullOrEmpty(' ')).toBe(false) - }) -}) - -describe('trimSpacesAndRemoveDoubleQuotes', () => { - it('should trim spaces and remove double quotes', () => { - expect(trimSpacesAndRemoveDoubleQuotes(' "text" ')).toBe('text') - expect(trimSpacesAndRemoveDoubleQuotes(' "text')).toBe('text') - expect(trimSpacesAndRemoveDoubleQuotes('text" ')).toBe('text') - expect(trimSpacesAndRemoveDoubleQuotes('text')).toBe('text') - }) - - it('should handle empty strings', () => { - expect(trimSpacesAndRemoveDoubleQuotes('')).toBe('') - }) -}) +import { stripGender, isNullOrEmpty, trimSpacesAndRemoveDoubleQuotes } from './string-utilities' + +describe('stripGender', () => { + it('should remove gender-related words and trim the string', () => { + expect(stripGender('Meisjes kleding')).toBe('kleding') + expect(stripGender('Jongens schoenen')).toBe('schoenen') + expect(stripGender('Vrouwen accessoires')).toBe('accessoires') + expect(stripGender('Mannen horloges')).toBe('horloges') + expect(stripGender('Unisex kleding')).toBe('Unisex kleding') // No gender-related word + }) + + it('should return an empty string for null or undefined values', () => { + expect(stripGender(null!)).toBe('') + expect(stripGender(undefined!)).toBe('') + }) +}) + +describe('isNullOrEmpty', () => { + it('should return true for undefined, null, or empty strings', () => { + expect(isNullOrEmpty(undefined!)).toBe(true) + expect(isNullOrEmpty(null!)).toBe(true) + expect(isNullOrEmpty('')).toBe(true) + }) + + it('should return false for non-empty strings', () => { + expect(isNullOrEmpty('text')).toBe(false) + expect(isNullOrEmpty(' ')).toBe(false) + }) +}) + +describe('trimSpacesAndRemoveDoubleQuotes', () => { + it('should trim spaces and remove double quotes', () => { + expect(trimSpacesAndRemoveDoubleQuotes(' "text" ')).toBe('text') + expect(trimSpacesAndRemoveDoubleQuotes(' "text')).toBe('text') + expect(trimSpacesAndRemoveDoubleQuotes('text" ')).toBe('text') + expect(trimSpacesAndRemoveDoubleQuotes('text')).toBe('text') + }) + + it('should handle empty strings', () => { + expect(trimSpacesAndRemoveDoubleQuotes('')).toBe('') + }) +}) diff --git a/src/string-utilities.ts b/src/string-utilities.ts index ebbaecf..3617c0a 100644 --- a/src/string-utilities.ts +++ b/src/string-utilities.ts @@ -1,5 +1,10 @@ -const regexGender = /Meisjes|Jongens|Vrouwen|Mannen/ -export const stripGender = (categorie: string) => categorie.replace(regexGender, '').trim() - -export const isNullOrEmpty = (text: string) => text === undefined || text === null || text.length <= 0 -export const trimSpacesAndRemoveDoubleQuotes = (text: string) => text.trim().split('"').join('') +const regexGender = /Meisjes|Jongens|Vrouwen|Mannen/ +export const stripGender = (categorie: string) => { + if (categorie === null || categorie === undefined) { + return '' + } + return categorie.replace(regexGender, '').trim() +} + +export const isNullOrEmpty = (text: string) => text === undefined || text === null || text.length <= 0 +export const trimSpacesAndRemoveDoubleQuotes = (text: string) => text.trim().split('"').join('')