Skip to content

Commit

Permalink
Merge pull request #285 from OpenBeta/kao-hardware-report
Browse files Browse the repository at this point in the history
Add hardwareReportLink for organizations
  • Loading branch information
zichongkao committed May 4, 2023
2 parents 68a0346 + 13c70ad commit ae37bbc
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 16 deletions.
16 changes: 13 additions & 3 deletions src/__tests__/organizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { AreaType } from '../db/AreaTypes.js'
import { OrgType, OrganizationType, OperationType, OrganizationEditableFieldsType } from '../db/OrganizationTypes.js'
import { changelogDataSource } from '../model/ChangeLogDataSource.js'
import { queryAPI, setUpServer } from '../utils/testUtils.js'
import { muuidToString, isMuuidHexStr } from '../utils/helpers.js'
import { muuidToString } from '../utils/helpers.js'
import { validate as validateMuuid } from 'uuid'

jest.setTimeout(60000)

Expand Down Expand Up @@ -72,6 +73,8 @@ describe('organizations API', () => {
email
donationLink
instagramLink
facebookLink
hardwareReportLink
description
}
}
Expand All @@ -90,7 +93,7 @@ describe('organizations API', () => {
expect(createResponse.statusCode).toBe(200)
const orgId = createResponse.body.data.organization.orgId
// orgId is MUUID scalar type which should always be serialized into the muuid hex string format.
expect(isMuuidHexStr(orgId)).toBeTruthy()
expect(validateMuuid(orgId)).toBeTruthy()
expect(createResponse.body.data.organization.orgType).toBe('LOCAL_CLIMBING_ORGANIZATION')
expect(createResponse.body.data.organization.displayName).toBe('Friends of Openbeta')
expect(createResponse.body.data.organization.associatedAreaIds).toStrictEqual([])
Expand All @@ -111,6 +114,8 @@ describe('organizations API', () => {
email: '[email protected]',
donationLink: 'https://donate.alliesofopenbeta.com',
instagramLink: 'https://instagram.com/alliesofopenbeta',
facebookLink: 'https://www.facebook.com/alliesofopenbeta',
hardwareReportLink: 'https://www.alliesofopenbeta.com/reporthardware',
description: 'We are allies of OpenBeta!'
}
},
Expand All @@ -128,6 +133,8 @@ describe('organizations API', () => {
expect(orgResult.content.email).toBe('[email protected]')
expect(orgResult.content.donationLink).toBe('https://donate.alliesofopenbeta.com')
expect(orgResult.content.instagramLink).toBe('https://instagram.com/alliesofopenbeta')
expect(orgResult.content.facebookLink).toBe('https://www.facebook.com/alliesofopenbeta')
expect(orgResult.content.hardwareReportLink).toBe('https://www.alliesofopenbeta.com/reporthardware')
expect(orgResult.content.description).toBe('We are allies of OpenBeta!')

// eslint-disable-next-line
Expand Down Expand Up @@ -180,6 +187,7 @@ describe('organizations API', () => {
donationLink
instagramLink
facebookLink
hardwareReportLink
description
}
}
Expand Down Expand Up @@ -207,7 +215,8 @@ describe('organizations API', () => {
associatedAreaIds: [ca.metadata.area_id, wa.metadata.area_id],
email: '[email protected]',
facebookLink: 'https://www.facebook.com/alphaopenbeta',
instagramLink: 'https://www.instagram.com/alphaopenbeta'
instagramLink: 'https://www.instagram.com/alphaopenbeta',
hardwareReportLink: 'https://alphaopenbeta.com/reporthardware'
}
alphaOrg = await organizations.addOrganization(user, OrgType.localClimbingOrganization, alphaFields)
.then((res: OrganizationType | null) => {
Expand Down Expand Up @@ -251,6 +260,7 @@ describe('organizations API', () => {
expect(orgResult.content.email).toBe(alphaFields.email)
expect(orgResult.content.instagramLink).toBe(alphaFields.instagramLink)
expect(orgResult.content.facebookLink).toBe(alphaFields.facebookLink)
expect(orgResult.content.hardwareReportLink).toBe(alphaFields.hardwareReportLink)
})

it('retrieves organizations using an exactMatch displayName filter', async () => {
Expand Down
1 change: 1 addition & 0 deletions src/db/OrganizationSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const ContentSchema = new Schema<IOrganizationContent>({
donationLink: { type: Schema.Types.String },
instagramLink: { type: Schema.Types.String },
facebookLink: { type: Schema.Types.String },
hardwareReportLink: { type: Schema.Types.String },
description: { type: Schema.Types.String }
}, { _id: false })

Expand Down
5 changes: 5 additions & 0 deletions src/db/OrganizationTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ export interface IOrganizationContent {
* URL of organization's Facebook page.
*/
facebookLink?: string
/**
* URL of where climbers can report bad hardware to the organization.
*/
hardwareReportLink?: string
/** longform to mediumform description of this organization.
*
* We expect org_admins to make a call about whatever kind of context may be appropriate
Expand All @@ -101,6 +105,7 @@ export interface OrganizationEditableFieldsType {
donationLink?: string
instagramLink?: string
facebookLink?: string
hardwareReportLink?: string
description?: string
}

Expand Down
1 change: 1 addition & 0 deletions src/graphql/schema/Organization.gql
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type OrganizationContent {
donationLink: String
instagramLink: String
facebookLink: String
hardwareReportLink: String
description: String
}

Expand Down
2 changes: 2 additions & 0 deletions src/graphql/schema/OrganizationEdit.gql
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ input AddOrganizationInput {
donationLink: String
instagramLink: String
facebookLink: String
hardwareReportLink: String
description: String
}

Expand All @@ -33,5 +34,6 @@ input OrganizationEditableFieldsInput {
donationLink: String
instagramLink: String
facebookLink: String
hardwareReportLink: String
description: String
}
3 changes: 2 additions & 1 deletion src/model/MutableOrganizationDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ const findNonexistantAreas = async (areaIds: MUUID[]): Promise<MUUID[]> => {
const sanitizeEditableFields = async (
document: OrganizationEditableFieldsType
): Promise<Partial<OrganizationType>> => {
const { associatedAreaIds, excludedAreaIds, displayName, website, email, donationLink, instagramLink, facebookLink, description } = document
const { associatedAreaIds, excludedAreaIds, displayName, website, email, donationLink, instagramLink, facebookLink, hardwareReportLink, description } = document
const orgFragment: Partial<OrganizationType> = {}

if (associatedAreaIds !== undefined && associatedAreaIds.length > 0) {
Expand All @@ -154,6 +154,7 @@ const sanitizeEditableFields = async (
if (donationLink !== undefined) { orgFragment['content.donationLink'] = sanitizeStrict(donationLink) }
if (instagramLink !== undefined) { orgFragment['content.instagramLink'] = sanitizeStrict(instagramLink) }
if (facebookLink !== undefined) { orgFragment['content.facebookLink'] = sanitizeStrict(facebookLink) }
if (hardwareReportLink !== undefined) { orgFragment['content.hardwareReportLink'] = sanitizeStrict(hardwareReportLink) }
if (description !== undefined) { orgFragment['content.description'] = sanitize(description) }

return orgFragment
Expand Down
3 changes: 3 additions & 0 deletions src/model/__tests__/MutableOrganizationDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ describe('Organization', () => {
donationLink: 'https://www.friendsofopenbeta.com/donate',
instagramLink: 'https://www.instagram.com/friendsofopenbeta',
facebookLink: 'https://www.facebook.com/friendsofopenbeta',
hardwareReportLink: 'https://www.friendsofopenbeta.com/reporthardware',
description: 'We are friends of openbeta.\nWe are a 503(B) corporation.'
}
emptyOrg = {
Expand Down Expand Up @@ -68,6 +69,7 @@ describe('Organization', () => {
expect(newOrg.content?.donationLink).toBe(document.donationLink)
expect(newOrg.content?.instagramLink).toBe(document.instagramLink)
expect(newOrg.content?.facebookLink).toBe(document.facebookLink)
expect(newOrg.content?.hardwareReportLink).toBe(document.hardwareReportLink)
expect(newOrg.content?.description).toBe(document.description)
expect(newOrg.associatedAreaIds.map(muuidToString)).toEqual([muuidToString(usa.metadata.area_id)])
expect(newOrg._change?.operation).toBe('addOrganization')
Expand Down Expand Up @@ -114,6 +116,7 @@ describe('Organization', () => {
expect(updatedOrg.content?.donationLink).toBe(document.donationLink)
expect(updatedOrg.content?.instagramLink).toBe(document.instagramLink)
expect(updatedOrg.content?.facebookLink).toBe(document.facebookLink)
expect(updatedOrg.content?.hardwareReportLink).toBe(document.hardwareReportLink)
expect(updatedOrg.content?.description).toBe(document.description)
expect(updatedOrg._change?.operation).toBe('updateOrganization')
expect(updatedOrg._change?.seq).toBe(0)
Expand Down
14 changes: 2 additions & 12 deletions src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,13 @@ export const isBase64Str = (s: string): boolean => {
return bc && lc
}

/**
* Detects if string is in uuid-mongodb's "relaxed" hex format.
* @param s input string
* @returns
*/
export const isMuuidHexStr = (s: string): boolean => {
const regex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/
return regex.test(s)
}

/**
* Ensures that type-checking errors out if enums are not
* handlded exhaustively in switch statements.
* handled exhaustively in switch statements.
* Eg.
* switch(val) {
* case enumOne:
* ...
* ...
* default:
* exhaustiveCheck(val)
* }
Expand Down

0 comments on commit ae37bbc

Please sign in to comment.