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

feat: Ice context #283

Merged
merged 1 commit into from
Jun 29, 2023
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions src/GradeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const gradeContextToGradeScales: Partial<Record<GradeContexts, ClimbGrade
mixed: GradeScales.YDS,
aid: GradeScales.YDS,
snow: GradeScales.YDS, // is this the same as alpine?
ice: GradeScales.YDS // is this the same as alpine?
ice: GradeScales.WI
},
[GradeContexts.US]: {
trad: GradeScales.YDS,
Expand All @@ -57,7 +57,7 @@ export const gradeContextToGradeScales: Partial<Record<GradeContexts, ClimbGrade
mixed: GradeScales.YDS,
aid: GradeScales.YDS,
snow: GradeScales.YDS, // is this the same as alpine?
ice: GradeScales.YDS // is this the same as alpine?
ice: GradeScales.WI
},
[GradeContexts.FR]: {
trad: GradeScales.FRENCH,
Expand All @@ -68,7 +68,7 @@ export const gradeContextToGradeScales: Partial<Record<GradeContexts, ClimbGrade
mixed: GradeScales.FRENCH,
aid: GradeScales.FRENCH,
snow: GradeScales.FRENCH, // is this the same as alpine?
ice: GradeScales.FRENCH // is this the same as alpine?
ice: GradeScales.WI
},
[GradeContexts.SA]: {
trad: GradeScales.FRENCH,
Expand All @@ -79,7 +79,7 @@ export const gradeContextToGradeScales: Partial<Record<GradeContexts, ClimbGrade
mixed: GradeScales.FRENCH,
aid: GradeScales.FRENCH,
snow: GradeScales.FRENCH, // SA does not have a whole lot of snow
ice: GradeScales.FRENCH // SA does not have a whole lot of ice
ice: GradeScales.WI
}
}

Expand Down
25 changes: 25 additions & 0 deletions src/__tests__/gradeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ describe('Test grade utilities', () => {
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()
Expand All @@ -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.')
Expand All @@ -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()
Expand All @@ -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()
Expand Down
36 changes: 31 additions & 5 deletions src/model/__tests__/MutableClimbDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ describe('Climb CRUD', () => {
disciplines: {
trad: true
}
},
{
name: 'Icy ice one',
disciplines: {
ice: true
}
}
]

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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' })
Expand All @@ -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)
}

{
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down