Skip to content

Commit d65db0f

Browse files
committed
Merge branch 'develop' into coco/#420
2 parents 49a1a5b + 795d3a1 commit d65db0f

File tree

15 files changed

+550
-12
lines changed

15 files changed

+550
-12
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![Build](https://gitlab.com/openbeta/openbeta-graphql/badges/develop/pipeline.svg)](https://gitlab.com/openbeta/openbeta-graphql/-/pipelines) [![License](https://img.shields.io/github/license/openbeta/openbeta-graphql?style=flat-square)](./LICENSE)
1+
c[![Build](https://gitlab.com/openbeta/openbeta-graphql/badges/develop/pipeline.svg)](https://gitlab.com/openbeta/openbeta-graphql/-/pipelines) [![License](https://img.shields.io/github/license/openbeta/openbeta-graphql?style=flat-square)](./LICENSE)
22
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
33
[![All Contributors](https://img.shields.io/badge/all_contributors-18-orange.svg?style=flat-square)](#contributors-)
44
<!-- ALL-CONTRIBUTORS-BADGE:END -->
@@ -65,6 +65,12 @@ query Example1 {
6565
```
6666

6767
### Development
68+
#### Installing mongodb
69+
70+
This step often trips up new devs. the install for most database engines can be little bit hairy, but mongodb is made a particular challenge by its lack of wide availability in common package managers. If you have docker installed, then your easiest bet is definitely to just do `docker compose up` when you need the persistent database. If that doesn't seem like fun to you, your next option is to get a binary [from their page directly](https://www.mongodb.com/try/download/community) they have wide platform support and you shouldn't have an issue finding one that will run for you.
71+
72+
When configuring it for development, it should be fine to leave auth disabled, since the data inside is not sensitive.
73+
6874
#### Requirements
6975

7076
- [Docker](https://docs.docker.com/get-docker)

src/GradeUtils.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,18 @@ export const getCountriesDefaultGradeContext = (): { [x: string]: GradeContexts
238238
return countries
239239
}
240240

241-
export const validDisciplines = ['trad', 'sport', 'bouldering', 'deepwatersolo', 'alpine', 'snow', 'ice', 'mixed', 'aid', 'tr']
241+
export const validDisciplines: Array<keyof DisciplineType> = [
242+
'trad',
243+
'sport',
244+
'bouldering',
245+
'deepwatersolo',
246+
'alpine',
247+
'snow',
248+
'ice',
249+
'mixed',
250+
'aid',
251+
'tr'
252+
]
242253

243254
/**
244255
* Perform runtime validation of climb discipline object

src/__tests__/media.e2e.ts

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
import { ApolloServer } from '@apollo/server'
2+
import muuid from 'uuid-mongodb'
3+
import { jest } from '@jest/globals'
4+
import MutableMediaDataSource from '../model/MutableMediaDataSource.js'
5+
import { MediaObject, MediaObjectGQLInput } from '../db/MediaObjectTypes.js'
6+
import { queryAPI, setUpServer } from '../utils/testUtils.js'
7+
import { muuidToString } from '../utils/helpers.js'
8+
import { InMemoryDB } from '../utils/inMemoryDB.js'
9+
import express from 'express'
10+
import UserDataSource from '../model/UserDataSource.js'
11+
12+
jest.setTimeout(60000)
13+
14+
describe('E2E tests to validate behavior of media queries', () => {
15+
let server: ApolloServer
16+
let user: muuid.MUUID
17+
let userUuid: string
18+
let app: express.Application
19+
let inMemoryDB: InMemoryDB
20+
let userDs: UserDataSource
21+
22+
beforeAll(async () => {
23+
({ server, inMemoryDB, app } = await setUpServer())
24+
// Auth0 serializes uuids in "relaxed" mode, resulting in this hex string format
25+
// "59f1d95a-627d-4b8c-91b9-389c7424cb54" instead of base64 "WfHZWmJ9S4yRuTicdCTLVA==".
26+
user = muuid.mode('relaxed').v4()
27+
userUuid = muuidToString(user)
28+
})
29+
30+
beforeEach(async () => {
31+
await inMemoryDB.clear()
32+
userDs = UserDataSource.getInstance()
33+
const res = await userDs.createOrUpdateUserProfile(user, {
34+
userUuid,
35+
username: 'iwannaclimbv17oneday',
36+
37+
displayName: 'jared'
38+
})
39+
expect(res).toBe(true)
40+
})
41+
42+
afterAll(async () => {
43+
await server.stop()
44+
await inMemoryDB.close()
45+
})
46+
47+
async function insertMediaObjects (mediaCount: number): Promise<MediaObject[]> {
48+
const newMediaListInput: MediaObjectGQLInput[] = []
49+
for (let i = 0; i < mediaCount; i++) {
50+
newMediaListInput.push({
51+
userUuid,
52+
width: 800,
53+
height: 600,
54+
format: 'jpeg',
55+
size: 45000,
56+
mediaUrl: `/areaPhoto${i}.jpg`
57+
})
58+
}
59+
60+
const media = MutableMediaDataSource.getInstance()
61+
return await media.addMediaObjects(newMediaListInput)
62+
}
63+
64+
describe('media queries', () => {
65+
it('can resolve known media', async () => {
66+
const [object] = await insertMediaObjects(1)
67+
const response = await queryAPI({
68+
query: `
69+
query Media($input: MediaInput) {
70+
media(input: $input) {
71+
id
72+
mediaUrl
73+
}
74+
}
75+
`,
76+
operationName: 'Media',
77+
variables: {
78+
input: {
79+
id: object._id.toString()
80+
}
81+
},
82+
userUuid,
83+
app
84+
})
85+
86+
expect(response.statusCode).toBe(200)
87+
expect(response.error).toBe(false)
88+
const mediaResult = response.body.data.media
89+
expect(mediaResult.id).toBe(object._id.toHexString())
90+
})
91+
92+
it('Media resolver can yield a simple username', async () => {
93+
const [object] = await insertMediaObjects(1)
94+
const response = await queryAPI({
95+
query: `
96+
query Media($input: MediaInput) {
97+
media(input: $input) {
98+
id
99+
mediaUrl
100+
username
101+
}
102+
}
103+
`,
104+
operationName: 'Media',
105+
variables: {
106+
input: {
107+
id: object._id.toString()
108+
}
109+
},
110+
userUuid,
111+
app
112+
})
113+
114+
expect(response.statusCode).toBe(200)
115+
expect(response.error).toBe(false)
116+
console.log(response)
117+
const mediaResult = response.body.data.media
118+
expect(mediaResult.id).toBe(object._id.toHexString())
119+
expect(mediaResult.mediaUrl).toBeTruthy()
120+
expect(mediaResult.username).not.toBeNull()
121+
expect(mediaResult.username).not.toBeUndefined()
122+
})
123+
124+
it('Media resolver can yield a user node', async () => {
125+
const [object] = await insertMediaObjects(1)
126+
const response = await queryAPI({
127+
query: `
128+
query Media($input: MediaInput) {
129+
media(input: $input) {
130+
id
131+
mediaUrl
132+
user {
133+
username
134+
}
135+
}
136+
}
137+
`,
138+
operationName: 'Media',
139+
variables: {
140+
input: {
141+
id: object._id.toString()
142+
}
143+
},
144+
userUuid,
145+
app
146+
})
147+
148+
expect(response.statusCode).toBe(200)
149+
expect(response.error).toBe(false)
150+
console.log(response)
151+
const mediaResult = response.body.data.media
152+
expect(mediaResult.id).toBe(object._id.toHexString())
153+
expect(mediaResult.mediaUrl).toBeTruthy()
154+
console.log(mediaResult)
155+
expect(mediaResult.user).not.toBeNull()
156+
expect(mediaResult.user.username).toBe('iwannaclimbv17oneday')
157+
})
158+
})
159+
})

0 commit comments

Comments
 (0)