Skip to content

Commit

Permalink
🍏 Add test for parse YMD function
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianpb committed May 27, 2024
1 parent f5df883 commit 4f3e1fa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
15 changes: 14 additions & 1 deletion backend/src/score.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ScoreResult, fuzzballTokenSetRatio } from './score';
import { ScoreResult, fuzzballTokenSetRatio, parseYMD } from './score';
import { describe, expect, it } from 'vitest'

describe('score.ts - Score function', () => {
Expand All @@ -8,6 +8,19 @@ describe('score.ts - Score function', () => {
expect(score).eq(1)
})

it('test parse year month day function', () => {
const parsedDate = parseYMD("20220304");
// returns the month (from 0 to 11)
const month = parsedDate.getMonth() + 1
// returns the day of the month (from 1 to 31)
const day = parsedDate.getDate()
// returns the year (four digits)
const year = parsedDate.getFullYear()
expect(month).eq(3)
expect(day).eq(4)
expect(year).eq(2022)
})

it('should return 0.8 as global score', () => {
const score = new ScoreResult({
name: {
Expand Down
9 changes: 5 additions & 4 deletions backend/src/score.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ const scoreCountry = (countryA: string|string[]|RequestField, countryB: string|s

let scoreLocation = (locA: Location, locB: Location, event?: string, explain?: any): any => {
const score: any = {};
const BisFrench = (locB.countryCode && (locB.countryCode === 'FRA'));
const isLocationInFrance = (locB.countryCode && (locB.countryCode === 'FRA'));
if (locA.code && locB.code) {
score.code = scoreLocationCode(locA.code, locB.codeHistory as string|string[]);
}
Expand All @@ -469,7 +469,7 @@ let scoreLocation = (locA: Location, locB: Location, event?: string, explain?: a
if (locA.latitude && locA.longitude) {
score.geo = scoreGeo(locA.latitude, locA.longitude, locB.latitude, locB.longitude)
}
if (BisFrench) {
if (isLocationInFrance) {
updateObjProp(explain, `${event}Country`, 'France')
if (normalize(locA.country as string|string[])) {
score.country = scoreCountry(locA.country, tokenize(locB.country as string));
Expand Down Expand Up @@ -549,15 +549,16 @@ let scoreLocation = (locA: Location, locB: Location, event?: string, explain?: a
}


const parseYMD = (dateString: string): Date => {
return new Date(+dateString.substring(0,4),+dateString.substring(4,2) - 1,+dateString.substring(6,2));
export const parseYMD = (dateString: string): Date => {
return new Date(+dateString.substring(0,4), +dateString.substring(4,6) - 1, +dateString.substring(6,8));
}

const scoreDateRaw = (dateRangeA: any, dateStringB: string, foreignDate: boolean, event: string, explain: any): number => {
if (/^00000000$/.test(dateStringB) || !dateStringB || !dateRangeA) {
return blindDateScore;
}
if (typeof(dateRangeA) === 'string') {
dateRangeA = dateRangeA.trim();
if (/^\s*$/.test(dateRangeA)) {
return blindDateScore;
}
Expand Down

0 comments on commit 4f3e1fa

Please sign in to comment.