-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: improve change testing and remove timeouts
- Loading branch information
Showing
27 changed files
with
671 additions
and
591 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<component name="ProjectRunConfigurationManager"> | ||
<configuration default="true" type="JavaScriptTestRunnerJest"> | ||
<node-interpreter value="project" /> | ||
<node-options value="--experimental-vm-modules" /> | ||
<jest-options value="--runInBand" /> | ||
<envs /> | ||
<scope-kind value="ALL" /> | ||
<method v="2" /> | ||
</configuration> | ||
</component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,32 @@ | ||
import { ApolloServer } from 'apollo-server-express' | ||
import {ApolloServer} from 'apollo-server-express' | ||
import muuid from 'uuid-mongodb' | ||
import { jest } from '@jest/globals' | ||
import {jest} from '@jest/globals' | ||
import MutableAreaDataSource from '../model/MutableAreaDataSource.js' | ||
import MutableOrganizationDataSource from '../model/MutableOrganizationDataSource.js' | ||
import MutableClimbDataSource from '../model/MutableClimbDataSource.js' | ||
import { AreaType } from '../db/AreaTypes.js' | ||
import { OrgType, OrganizationType } from '../db/OrganizationTypes.js' | ||
import { muuidToString } from '../utils/helpers.js' | ||
import { queryAPI, setUpServer } from '../utils/testUtils.js' | ||
import {AreaType} from '../db/AreaTypes.js' | ||
import {OrganizationType, OrgType} from '../db/OrganizationTypes.js' | ||
import {muuidToString} from '../utils/helpers.js' | ||
import {queryAPI, setUpServer} from '../utils/testUtils.js' | ||
import {InMemoryDB} from "../utils/inMemoryDB.js"; | ||
import express from "express"; | ||
|
||
jest.setTimeout(60000) | ||
|
||
describe('history API', () => { | ||
let server: ApolloServer | ||
let user: muuid.MUUID | ||
let userUuid: string | ||
let inMemoryDB | ||
let app: express.Application | ||
let inMemoryDB: InMemoryDB | ||
|
||
// Mongoose models for mocking pre-existing state. | ||
let areas: MutableAreaDataSource | ||
let organizations: MutableOrganizationDataSource | ||
let climbs: MutableClimbDataSource | ||
|
||
beforeAll(async () => { | ||
({ server, inMemoryDB } = await setUpServer()) | ||
({server, inMemoryDB, app} = await setUpServer()) | ||
// Auth0 serializes uuids in "relaxed" mode, resulting in this hex string format | ||
// "59f1d95a-627d-4b8c-91b9-389c7424cb54" instead of base64 "WfHZWmJ9S4yRuTicdCTLVA==". | ||
user = muuid.mode('relaxed').v4() | ||
|
@@ -101,13 +104,14 @@ describe('history API', () => { | |
email: '[email protected]' | ||
} | ||
alphaOrg = await organizations.addOrganization(user, OrgType.localClimbingOrganization, alphaFields) | ||
climbIds = await climbs.addOrUpdateClimbs(user, ca.metadata.area_id, [{ name: 'Alpha Climb' }]) | ||
climbIds = await climbs.addOrUpdateClimbs(user, ca.metadata.area_id, [{name: 'Alpha Climb'}]) | ||
|
||
// Query for changes and ensure they are tracked. | ||
const resp = await queryAPI({ | ||
query: QUERY_RECENT_CHANGE_HISTORY, | ||
variables: { filter: {} }, | ||
userUuid | ||
variables: {filter: {}}, | ||
userUuid, | ||
app | ||
}) | ||
expect(resp.statusCode).toBe(200) | ||
const histories = resp.body.data.getChangeHistory | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
import { ApolloServer } from 'apollo-server-express' | ||
import {ApolloServer} from 'apollo-server-express' | ||
import muuid from 'uuid-mongodb' | ||
import { jest } from '@jest/globals' | ||
import MutableAreaDataSource from '../model/MutableAreaDataSource.js' | ||
import MutableOrganizationDataSource from '../model/MutableOrganizationDataSource.js' | ||
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 } from '../utils/helpers.js' | ||
import { validate as validateMuuid } from 'uuid' | ||
|
||
jest.setTimeout(110000) | ||
import {AreaType} from '../db/AreaTypes.js' | ||
import {OperationType, OrganizationEditableFieldsType, OrganizationType, OrgType} from '../db/OrganizationTypes.js' | ||
import {changelogDataSource} from '../model/ChangeLogDataSource.js' | ||
import {queryAPI, setUpServer} from '../utils/testUtils.js' | ||
import {muuidToString} from '../utils/helpers.js' | ||
import {validate as validateMuuid} from 'uuid' | ||
import {InMemoryDB} from "../utils/inMemoryDB.js"; | ||
import express from "express"; | ||
|
||
describe('organizations API', () => { | ||
let server: ApolloServer | ||
let user: muuid.MUUID | ||
let userUuid: string | ||
let inMemoryDB | ||
let app: express.Application | ||
let inMemoryDB: InMemoryDB | ||
|
||
// Mongoose models for mocking pre-existing state. | ||
let areas: MutableAreaDataSource | ||
|
@@ -26,7 +26,7 @@ describe('organizations API', () => { | |
let wa: AreaType | ||
|
||
beforeAll(async () => { | ||
({ server, inMemoryDB } = await setUpServer()) | ||
({server, inMemoryDB, app} = await setUpServer()) | ||
// Auth0 serializes uuids in "relaxed" mode, resulting in this hex string format | ||
// "59f1d95a-627d-4b8c-91b9-389c7424cb54" instead of base64 "WfHZWmJ9S4yRuTicdCTLVA==". | ||
user = muuid.mode('relaxed').v4() | ||
|
@@ -43,8 +43,8 @@ describe('organizations API', () => { | |
}) | ||
|
||
afterAll(async () => { | ||
await server.stop() | ||
await inMemoryDB.close() | ||
await server?.stop() | ||
await inMemoryDB?.close() | ||
}) | ||
|
||
describe('mutations', () => { | ||
|
@@ -85,9 +85,10 @@ describe('organizations API', () => { | |
const createResponse = await queryAPI({ | ||
query: createQuery, | ||
operationName: 'addOrganization', | ||
variables: { input: { displayName: 'Friends of Openbeta', orgType: 'LOCAL_CLIMBING_ORGANIZATION' } }, | ||
variables: {input: {displayName: 'Friends of Openbeta', orgType: 'LOCAL_CLIMBING_ORGANIZATION'}}, | ||
userUuid, | ||
roles: ['user_admin'] | ||
roles: ['user_admin'], | ||
app | ||
}) | ||
|
||
expect(createResponse.statusCode).toBe(200) | ||
|
@@ -120,7 +121,8 @@ describe('organizations API', () => { | |
} | ||
}, | ||
userUuid, | ||
roles: ['user_admin'] | ||
roles: ['user_admin'], | ||
app | ||
}) | ||
expect(updateResponse.statusCode).toBe(200) | ||
expect(updateResponse.body.errors).toBeUndefined() | ||
|
@@ -163,9 +165,10 @@ describe('organizations API', () => { | |
const response = await queryAPI({ | ||
query: createQuery, | ||
operationName: 'addOrganization', | ||
variables: { input: { displayName: 'Friends of Openbeta', orgType: 'LOCAL_CLIMBING_ORGANIZATION' } }, | ||
variables: {input: {displayName: 'Friends of Openbeta', orgType: 'LOCAL_CLIMBING_ORGANIZATION'}}, | ||
userUuid, | ||
roles: ['editor'] | ||
roles: ['editor'], | ||
app | ||
}) | ||
expect(response.statusCode).toBe(200) | ||
expect(response.body.data.organization).toBeNull() | ||
|
@@ -219,39 +222,40 @@ describe('organizations API', () => { | |
hardwareReportLink: 'https://alphaopenbeta.com/reporthardware' | ||
} | ||
alphaOrg = await organizations.addOrganization(user, OrgType.localClimbingOrganization, alphaFields) | ||
.then((res: OrganizationType | null) => { | ||
if (res === null) throw new Error('Failure mocking organization.') | ||
return res | ||
}) | ||
.then((res: OrganizationType | null) => { | ||
if (res === null) throw new Error('Failure mocking organization.') | ||
return res | ||
}) | ||
|
||
deltaFields = { | ||
displayName: 'Delta OpenBeta Club', | ||
email: '[email protected]' | ||
} | ||
deltaOrg = await organizations.addOrganization(user, OrgType.localClimbingOrganization, deltaFields) | ||
.then((res: OrganizationType | null) => { | ||
if (res === null) throw new Error('Failure mocking organization.') | ||
return res | ||
}) | ||
.then((res: OrganizationType | null) => { | ||
if (res === null) throw new Error('Failure mocking organization.') | ||
return res | ||
}) | ||
|
||
gammaFields = { | ||
displayName: 'Delta Gamma OpenBeta Club', | ||
description: 'We are an offshoot of the delta club.\nSee our website for more details.', | ||
excludedAreaIds: [wa.metadata.area_id] | ||
} | ||
gammaOrg = await organizations.addOrganization(user, OrgType.localClimbingOrganization, gammaFields) | ||
.then((res: OrganizationType | null) => { | ||
if (res === null) throw new Error('Failure mocking organization.') | ||
return res | ||
}) | ||
.then((res: OrganizationType | null) => { | ||
if (res === null) throw new Error('Failure mocking organization.') | ||
return res | ||
}) | ||
}) | ||
|
||
it('retrieves an organization with an MUUID', async () => { | ||
const response = await queryAPI({ | ||
query: organizationQuery, | ||
operationName: 'organization', | ||
variables: { input: muuidToString(alphaOrg.orgId) }, | ||
userUuid | ||
variables: {input: muuidToString(alphaOrg.orgId)}, | ||
userUuid, | ||
app | ||
}) | ||
expect(response.statusCode).toBe(200) | ||
const orgResult = response.body.data.organization | ||
|
@@ -268,8 +272,9 @@ describe('organizations API', () => { | |
const response = await queryAPI({ | ||
query: organizationsQuery, | ||
operationName: 'organizations', | ||
variables: { filter: { displayName: { match: 'Delta OpenBeta Club', exactMatch: true } } }, | ||
userUuid | ||
variables: {filter: {displayName: {match: 'Delta OpenBeta Club', exactMatch: true}}}, | ||
userUuid, | ||
app | ||
}) | ||
|
||
expect(response.statusCode).toBe(200) | ||
|
@@ -282,8 +287,9 @@ describe('organizations API', () => { | |
const response = await queryAPI({ | ||
query: organizationsQuery, | ||
operationName: 'organizations', | ||
variables: { filter: { displayName: { match: 'delta', exactMatch: false } } }, | ||
userUuid | ||
variables: {filter: {displayName: {match: 'delta', exactMatch: false}}}, | ||
userUuid, | ||
app | ||
}) | ||
expect(response.statusCode).toBe(200) | ||
const dataResult = response.body.data.organizations | ||
|
@@ -298,7 +304,8 @@ describe('organizations API', () => { | |
variables: { | ||
limit: 1 | ||
}, | ||
userUuid | ||
userUuid, | ||
app | ||
}) | ||
expect(response.statusCode).toBe(200) | ||
const dataResult = response.body.data.organizations | ||
|
@@ -309,8 +316,9 @@ describe('organizations API', () => { | |
const response = await queryAPI({ | ||
query: organizationsQuery, | ||
operationName: 'organizations', | ||
variables: { filter: { associatedAreaIds: { includes: [muuidToString(ca.metadata.area_id)] } } }, | ||
userUuid | ||
variables: {filter: {associatedAreaIds: {includes: [muuidToString(ca.metadata.area_id)]}}}, | ||
userUuid, | ||
app | ||
}) | ||
// Graphql should convert `includes` from a string[] to MUUID[] | ||
expect(response.statusCode).toBe(200) | ||
|
@@ -323,8 +331,9 @@ describe('organizations API', () => { | |
const response = await queryAPI({ | ||
query: organizationsQuery, | ||
operationName: 'organizations', | ||
variables: { filter: { excludedAreaIds: { excludes: [muuidToString(wa.metadata.area_id)] } } }, | ||
userUuid | ||
variables: {filter: {excludedAreaIds: {excludes: [muuidToString(wa.metadata.area_id)]}}}, | ||
userUuid, | ||
app | ||
}) | ||
expect(response.statusCode).toBe(200) | ||
const dataResult = response.body.data.organizations | ||
|
Oops, something went wrong.