From 49b21bd34cf1d00f000217ad4ee2a20027bcc555 Mon Sep 17 00:00:00 2001 From: Nathan Musoke Date: Wed, 3 May 2023 16:27:14 -0400 Subject: [PATCH] feat: Ice context The grade contexts know nothing about ice climbing grades. Instead, they use sport/trad grades. Add support for ice climbs with WI grades. This commit assumes that all contexts use only Winter Ice grades. This does not completely reflect real world usage - single regions often have a mix of WI and AI grades. In the short term, this could be overriden for local areas. Longer term, ice grades allowed in these contexts should be either of `GradeScales.AI` and `GradeScales.WI`. --- package.json | 2 +- src/GradeUtils.ts | 8 ++--- src/__tests__/gradeUtils.ts | 25 +++++++++++++ src/model/__tests__/MutableClimbDataSource.ts | 36 ++++++++++++++++--- yarn.lock | 8 ++--- 5 files changed, 65 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index bdb9ac69..2a493965 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "@babel/runtime": "^7.17.2", "@google-cloud/storage": "^6.9.5", "@graphql-tools/schema": "^8.3.1", - "@openbeta/sandbag": "^0.0.37", + "@openbeta/sandbag": "^0.0.45", "@turf/area": "^6.5.0", "@turf/bbox": "^6.5.0", "@turf/bbox-polygon": "^6.5.0", 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() @@ -61,6 +66,16 @@ describe('Test grade utilities', () => { expect(actual).toBeUndefined() }) + it.failing('can alpine ice grades to climbs with discipline ice', () => { + const context = gradeContextToGradeScales.US + if (context == null) fail('Bad grade context. Should not happen.') + + const actual = createGradeObject('AI2', sanitizeDisciplines({ ice: true }), context) + expect(actual).toEqual({ + ai: 'AI2' + }) + }) + it('creates grade object correctly in AU context', () => { const context = gradeContextToGradeScales.AU if (context == null) fail('Bad grade context. Should not happen.') @@ -75,6 +90,11 @@ describe('Test grade utilities', () => { vscale: 'v11' }) + actual = createGradeObject('WI4+', sanitizeDisciplines({ ice: true }), context) + expect(actual).toEqual({ + wi: 'WI4+' + }) + // Invalid input actual = createGradeObject('5.9', sanitizeDisciplines({ sport: true }), context) expect(actual).toBeUndefined() @@ -94,6 +114,11 @@ describe('Test grade utilities', () => { font: '7c' }) + actual = createGradeObject('WI6', sanitizeDisciplines({ ice: true }), context) + expect(actual).toEqual({ + wi: 'WI6' + }) + // 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 eebf4f2a..140b8cc6 100644 --- a/src/model/__tests__/MutableClimbDataSource.ts +++ b/src/model/__tests__/MutableClimbDataSource.ts @@ -44,6 +44,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) } { diff --git a/yarn.lock b/yarn.lock index b47674cb..371592ce 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1579,10 +1579,10 @@ "@nodelib/fs.scandir" "2.1.5" fastq "^1.6.0" -"@openbeta/sandbag@^0.0.37": - version "0.0.37" - resolved "https://registry.yarnpkg.com/@openbeta/sandbag/-/sandbag-0.0.37.tgz#59befbb2bace586be19c0a3c6d9f8046c05fa05e" - integrity sha512-oeCqXAZkvgHkUOHZefhZyftxsarcdHUtS2oEttIACCRpZ/Vs2hAmyXIn1Yg7dxnQEKbJ3TtVD4trUmNoJSolag== +"@openbeta/sandbag@^0.0.45": + version "0.0.45" + resolved "https://registry.yarnpkg.com/@openbeta/sandbag/-/sandbag-0.0.45.tgz#b6230ddf63f265b91d0a0359a2f87c5359dded74" + integrity sha512-8s2YFeUBU3lK2EzQIZSsf/apEIaxhtHJNfWWDmtjIE7/wlgqm84BSX72wur1FGrqcI9o3P1dkZmevHnu0ItGZQ== "@panva/asn1.js@^1.0.0": version "1.0.0"