mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-12 23:35:58 +00:00
refactor(modules): Various import fixes
* DRY schema stitching code * Use same `.env` configuration file for cypress tests That last part I couldn't improve a lot. I thought it might be possible with cypress to import all files from a folder. But since it must be browser compatible and our backend is not using webpack or anything, it remains a goal unreached. close #2773 close #2774
This commit is contained in:
parent
26dca113f0
commit
178143dfb7
@ -7,7 +7,7 @@
|
||||
"build": "babel src/ -d dist/ --copy-files",
|
||||
"start": "node dist/",
|
||||
"dev": "nodemon --exec babel-node src/ -e js,gql",
|
||||
"dev:debug": "nodemon --exec babel-node --inspect=0.0.0.0:9229 src/index.js -e js,gql",
|
||||
"dev:debug": "nodemon --exec babel-node --inspect=0.0.0.0:9229 src/ -e js,gql",
|
||||
"lint": "eslint src --config .eslintrc.js",
|
||||
"test": "jest --forceExit --detectOpenHandles --runInBand",
|
||||
"db:reset": "babel-node src/seed/reset-db.js",
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
import dotenv from 'dotenv'
|
||||
import path from 'path'
|
||||
|
||||
dotenv.config({ path: path.resolve(__dirname, '../../.env') })
|
||||
if (require.resolve) {
|
||||
// are we in a nodejs environment?
|
||||
dotenv.config({ path: require.resolve('../../.env') })
|
||||
}
|
||||
|
||||
const {
|
||||
MAPBOX_TOKEN,
|
||||
@ -27,6 +28,15 @@ export const requiredConfigs = {
|
||||
PRIVATE_KEY_PASSPHRASE,
|
||||
}
|
||||
|
||||
if (require.resolve) {
|
||||
// are we in a nodejs environment?
|
||||
Object.entries(requiredConfigs).map(entry => {
|
||||
if (!entry[1]) {
|
||||
throw new Error(`ERROR: "${entry[0]}" env variable is missing.`)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export const smtpConfigs = {
|
||||
SMTP_HOST,
|
||||
SMTP_PORT,
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
module.exports = {
|
||||
export default {
|
||||
id: { type: 'string', primary: true, lowercase: true },
|
||||
status: { type: 'string', valid: ['permanent', 'temporary'] },
|
||||
type: { type: 'string', valid: ['role', 'crowdfunding'] },
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import uuid from 'uuid/v4'
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
id: { type: 'string', primary: true, default: uuid },
|
||||
name: { type: 'string', required: true, default: false },
|
||||
slug: { type: 'string' },
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import uuid from 'uuid/v4'
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
id: { type: 'string', primary: true, default: uuid },
|
||||
createdAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() },
|
||||
updatedAt: {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import uuid from 'uuid/v4'
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
id: { type: 'string', primary: true, default: uuid },
|
||||
goal: { type: 'number' },
|
||||
progress: { type: 'number' },
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
module.exports = {
|
||||
export default {
|
||||
email: { type: 'string', primary: true, lowercase: true, email: true },
|
||||
createdAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() },
|
||||
verifiedAt: { type: 'string', isoDate: true },
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
module.exports = {
|
||||
export default {
|
||||
createdAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() },
|
||||
token: { type: 'string', primary: true, token: true },
|
||||
generatedBy: {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
module.exports = {
|
||||
export default {
|
||||
id: { type: 'string', primary: true },
|
||||
lat: { type: 'number' },
|
||||
lng: { type: 'number' },
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import uuid from 'uuid/v4'
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
id: { type: 'string', primary: true, default: uuid },
|
||||
activityId: { type: 'string', allow: [null] },
|
||||
objectId: { type: 'string', allow: [null] },
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import uuid from 'uuid/v4'
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
id: { type: 'string', primary: true, default: uuid },
|
||||
createdAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() },
|
||||
updatedAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() },
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import uuid from 'uuid/v4'
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
id: { type: 'string', primary: true, default: uuid },
|
||||
url: { type: 'string', uri: true, required: true },
|
||||
createdAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() },
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
module.exports = {
|
||||
export default {
|
||||
id: { type: 'string', primary: true },
|
||||
deleted: { type: 'boolean', default: false },
|
||||
disabled: { type: 'boolean', default: false },
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
module.exports = {
|
||||
export default {
|
||||
email: { type: 'string', primary: true, lowercase: true, email: true },
|
||||
createdAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() },
|
||||
nonce: { type: 'string', token: true },
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import uuid from 'uuid/v4'
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
id: { type: 'string', primary: true, default: uuid }, // TODO: should be type: 'uuid' but simplified for our tests
|
||||
actorId: { type: 'string', allow: [null] },
|
||||
name: { type: 'string', disallow: [null], min: 3 },
|
||||
|
||||
@ -1,16 +1,16 @@
|
||||
// NOTE: We cannot use `fs` here to clean up the code. Cypress breaks on any npm
|
||||
// module that is not browser-compatible. Node's `fs` module is server-side only
|
||||
export default {
|
||||
Badge: require('./Badge.js'),
|
||||
User: require('./User.js'),
|
||||
EmailAddress: require('./EmailAddress.js'),
|
||||
UnverifiedEmailAddress: require('./UnverifiedEmailAddress.js'),
|
||||
SocialMedia: require('./SocialMedia.js'),
|
||||
Post: require('./Post.js'),
|
||||
Comment: require('./Comment.js'),
|
||||
Category: require('./Category.js'),
|
||||
Tag: require('./Tag.js'),
|
||||
Location: require('./Location.js'),
|
||||
Donations: require('./Donations.js'),
|
||||
Report: require('./Report.js'),
|
||||
Badge: require('./Badge.js').default,
|
||||
User: require('./User.js').default,
|
||||
EmailAddress: require('./EmailAddress.js').default,
|
||||
UnverifiedEmailAddress: require('./UnverifiedEmailAddress.js').default,
|
||||
SocialMedia: require('./SocialMedia.js').default,
|
||||
Post: require('./Post.js').default,
|
||||
Comment: require('./Comment.js').default,
|
||||
Category: require('./Category.js').default,
|
||||
Tag: require('./Tag.js').default,
|
||||
Location: require('./Location.js').default,
|
||||
Donations: require('./Donations.js').default,
|
||||
Report: require('./Report.js').default,
|
||||
}
|
||||
|
||||
@ -1,30 +1,5 @@
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import { mergeTypes } from 'merge-graphql-schemas'
|
||||
|
||||
const findGqlFiles = dir => {
|
||||
var results = []
|
||||
var list = fs.readdirSync(dir)
|
||||
list.forEach(file => {
|
||||
file = path.join(dir, file).toString('utf-8')
|
||||
var stat = fs.statSync(file)
|
||||
if (stat && stat.isDirectory()) {
|
||||
// Recurse into a subdirectory
|
||||
results = results.concat(findGqlFiles(file))
|
||||
} else {
|
||||
if (path.extname(file) === '.gql') {
|
||||
// Is a gql file
|
||||
results.push(file)
|
||||
}
|
||||
}
|
||||
})
|
||||
return results
|
||||
}
|
||||
|
||||
const typeDefs = []
|
||||
|
||||
findGqlFiles(__dirname).forEach(file => {
|
||||
typeDefs.push(fs.readFileSync(file).toString('utf-8'))
|
||||
})
|
||||
import { mergeTypes, fileLoader } from 'merge-graphql-schemas'
|
||||
|
||||
const typeDefs = fileLoader(path.join(__dirname, './**/*.gql'))
|
||||
export default mergeTypes(typeDefs, { all: true })
|
||||
|
||||
@ -1,30 +1,18 @@
|
||||
import { getDriver, getNeode } from '../../bootstrap/neo4j'
|
||||
import createBadge from './badges.js'
|
||||
import createUser from './users.js'
|
||||
import createPost from './posts.js'
|
||||
import createComment from './comments.js'
|
||||
import createCategory from './categories.js'
|
||||
import createTag from './tags.js'
|
||||
import createSocialMedia from './socialMedia.js'
|
||||
import createLocation from './locations.js'
|
||||
import createEmailAddress from './emailAddresses.js'
|
||||
import createDonations from './donations.js'
|
||||
import createUnverifiedEmailAddresss from './unverifiedEmailAddresses.js'
|
||||
import createReport from './reports.js'
|
||||
|
||||
const factories = {
|
||||
Badge: createBadge,
|
||||
User: createUser,
|
||||
Post: createPost,
|
||||
Comment: createComment,
|
||||
Category: createCategory,
|
||||
Tag: createTag,
|
||||
SocialMedia: createSocialMedia,
|
||||
Location: createLocation,
|
||||
EmailAddress: createEmailAddress,
|
||||
UnverifiedEmailAddress: createUnverifiedEmailAddresss,
|
||||
Donations: createDonations,
|
||||
Report: createReport,
|
||||
Badge: require('./badges.js').default,
|
||||
User: require('./users.js').default,
|
||||
Post: require('./posts.js').default,
|
||||
Comment: require('./comments.js').default,
|
||||
Category: require('./categories.js').default,
|
||||
Tag: require('./tags.js').default,
|
||||
SocialMedia: require('./socialMedia.js').default,
|
||||
Location: require('./locations.js').default,
|
||||
EmailAddress: require('./emailAddresses.js').default,
|
||||
UnverifiedEmailAddress: require('./unverifiedEmailAddresses.js').default,
|
||||
Donations: require('./donations.js').default,
|
||||
Report: require('./reports.js').default,
|
||||
}
|
||||
|
||||
export const cleanDatabase = async (options = {}) => {
|
||||
@ -34,7 +22,7 @@ export const cleanDatabase = async (options = {}) => {
|
||||
await session.writeTransaction(transaction => {
|
||||
return transaction.run(
|
||||
`
|
||||
MATCH (everything)
|
||||
MATCH (everything)
|
||||
DETACH DELETE everything
|
||||
`,
|
||||
)
|
||||
|
||||
@ -1,21 +1,13 @@
|
||||
import express from 'express'
|
||||
import helmet from 'helmet'
|
||||
import { ApolloServer } from 'apollo-server-express'
|
||||
import CONFIG, { requiredConfigs } from './config'
|
||||
import CONFIG from './config'
|
||||
import middleware from './middleware'
|
||||
import { getNeode, getDriver } from './bootstrap/neo4j'
|
||||
import decode from './jwt/decode'
|
||||
import schema from './schema'
|
||||
import webfinger from './activitypub/routes/webfinger'
|
||||
|
||||
// check required configs and throw error
|
||||
// TODO check this directly in config file - currently not possible due to testsetup
|
||||
Object.entries(requiredConfigs).map(entry => {
|
||||
if (!entry[1]) {
|
||||
throw new Error(`ERROR: "${entry[0]}" env variable is missing.`)
|
||||
}
|
||||
})
|
||||
|
||||
const driver = getDriver()
|
||||
const neode = getNeode()
|
||||
|
||||
|
||||
@ -11,10 +11,19 @@
|
||||
// This function is called when a project is opened or re-opened (e.g. due to
|
||||
// the project's config changing)
|
||||
|
||||
|
||||
const cucumber = require('cypress-cucumber-preprocessor').default
|
||||
module.exports = on => {
|
||||
const dotenv = require('dotenv')
|
||||
|
||||
module.exports = (on, config) => {
|
||||
// (on, config) => {
|
||||
// `on` is used to hook into various events Cypress emits
|
||||
// `config` is the resolved Cypress config
|
||||
const { parsed } = dotenv.config({ path: require.resolve('../../backend/.env') })
|
||||
config.env.NEO4J_URI = parsed.NEO4J_URI
|
||||
config.env.NEO4J_USERNAME = parsed.NEO4J_USERNAME
|
||||
config.env.NEO4J_PASSWORD = parsed.NEO4J_PASSWORD
|
||||
|
||||
on('file:preprocessor', cucumber())
|
||||
return config
|
||||
}
|
||||
|
||||
@ -1,9 +1,13 @@
|
||||
import Factory from '../../backend/src/seed/factories'
|
||||
import { getDriver, getNeode } from '../../backend/src/bootstrap/neo4j'
|
||||
import neode from 'neode'
|
||||
|
||||
const neo4jDriver = getDriver()
|
||||
const neodeInstance = getNeode()
|
||||
const neo4jConfigs = {
|
||||
uri: Cypress.env('NEO4J_URI'),
|
||||
username: Cypress.env('NEO4J_USERNAME'),
|
||||
password: Cypress.env('NEO4J_PASSWORD')
|
||||
}
|
||||
const neo4jDriver = getDriver(neo4jConfigs)
|
||||
const neodeInstance = getNeode(neo4jConfigs)
|
||||
const factoryOptions = { neo4jDriver, neodeInstance }
|
||||
const factory = Factory(factoryOptions)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user