From cc6bdfae10ba818adc66e1f3ef3654a6e53648ae Mon Sep 17 00:00:00 2001 From: Nathan Musoke Date: Wed, 3 May 2023 16:27:14 -0400 Subject: [PATCH] feat: Ice context This adds basic support for ice climbs with the WI grade scales. This currently assumes that all contexts use only Winter Ice grades rather than a mix of Alpine Ice and Winter Ice. This is not the case; the grade scale depends on the local climate. To enable AI grades in future, the ice grades allowed in most contexts should be an array: `[GradeScales.AI, GradeScales.WI]`. --- src/GradeUtils.ts | 8 ++--- src/__tests__/gradeUtils.ts | 15 ++++++++ src/model/__tests__/MutableClimbDataSource.ts | 36 ++++++++++++++++--- 3 files changed, 50 insertions(+), 9 deletions(-) diff --git a/src/GradeUtils.ts b/src/GradeUtils.ts index feac6bef..60628af0 100644 --- a/src/GradeUtils.ts +++ b/src/GradeUtils.ts @@ -46,7 +46,7 @@ export const gradeContextToGradeScales: Partial { vscale: 'V4' }) + actual = createGradeObject('WI2', sanitizeDisciplines({ ice: true }), context) + expect(actual).toEqual({ + wi: 'WI2' + }) + // mismatch input and discipline actual = createGradeObject('V4', sanitizeDisciplines({ trad: true }), context) expect(actual).toBeUndefined() @@ -75,6 +80,11 @@ describe('Test grade utilities', () => { vscale: 'v11' }) + actual = createGradeObject('WI2', sanitizeDisciplines({ ice: true }), context) + expect(actual).toEqual({ + wi: 'WI2' + }) + // Invalid input actual = createGradeObject('5.9', sanitizeDisciplines({ sport: true }), context) expect(actual).toBeUndefined() @@ -94,6 +104,11 @@ describe('Test grade utilities', () => { font: '7c' }) + actual = createGradeObject('WI2', sanitizeDisciplines({ ice: true }), context) + expect(actual).toEqual({ + wi: 'WI2' + }) + // Invalid input actual = createGradeObject('5.9', sanitizeDisciplines({ bouldering: true }), context) expect(actual).toBeUndefined() diff --git a/src/model/__tests__/MutableClimbDataSource.ts b/src/model/__tests__/MutableClimbDataSource.ts index bd900818..541ef6ce 100644 --- a/src/model/__tests__/MutableClimbDataSource.ts +++ b/src/model/__tests__/MutableClimbDataSource.ts @@ -34,6 +34,12 @@ describe('Climb CRUD', () => { disciplines: { trad: true } + }, + { + name: 'Icy ice one', + disciplines: { + ice: true + } } ] @@ -73,6 +79,14 @@ describe('Climb CRUD', () => { grade: '5c' } + const newIceRoute: ClimbChangeInputType = { + name: 'Cool Ice line', + disciplines: { + ice: true + }, + grade: 'WI8+' + } + beforeAll(async () => { await connectDB() stream = await streamListener() @@ -247,14 +261,19 @@ describe('Climb CRUD', () => { const newClimbingArea = await areas.addArea(testUser, 'Climbing area 1', null, 'aus') if (newClimbingArea == null) fail('Expect new area to be created') + const newclimbs = [ + { ...newSportClimb1, grade: '17' }, // good sport grade + { ...newSportClimb2, grade: '29/30', disciplines: { trad: true } }, // good trad and slash grade + { ...newSportClimb2, grade: '5.9' }, // bad AU context grade + { ...newIceRoute, grade: 'WI4+' } // good WI AU context grade + ] + const newIDs = await climbs.addOrUpdateClimbs( testUser, newClimbingArea.metadata.area_id, - [{ ...newSportClimb1, grade: '17' }, // good sport grade - { ...newSportClimb2, grade: '29/30', disciplines: { trad: true } }, // good trad and slash grade - { ...newSportClimb2, grade: '5.9' }]) // bad AU context grade - - expect(newIDs).toHaveLength(3) + newclimbs + ) + expect(newIDs).toHaveLength(newclimbs.length) const climb1 = await climbs.findOneClimbByMUUID(muid.from(newIDs[0])) expect(climb1?.grades).toEqual({ ewbank: '17' }) @@ -267,6 +286,13 @@ describe('Climb CRUD', () => { const climb3 = await climbs.findOneClimbByMUUID(muid.from(newIDs[2])) expect(climb3?.grades).toEqual(undefined) + + const climb4 = await climbs.findOneClimbByMUUID(muid.from(newIDs[3])) + expect(climb4?.grades).toEqual({ wi: 'WI4+' }) + expect(climb4?.type.sport).toBe(false) + expect(climb4?.type.trad).toBe(false) + expect(climb4?.type.bouldering).toBe(false) + expect(climb4?.type.ice).toBe(true) } {