Merge branch 'master' into fix-create-post-notifications

This commit is contained in:
Ulf Gebhardt 2023-07-07 07:48:22 +02:00 committed by GitHub
commit b0a9c19143
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 2673 additions and 1469 deletions

View File

@ -1,25 +1,219 @@
module.exports = {
root: true,
env: {
es6: true,
// es6: true,
node: true,
jest: true
},
parserOptions: {
/* parserOptions: {
parser: 'babel-eslint'
},
},*/
parser: '@typescript-eslint/parser',
plugins: ['prettier', '@typescript-eslint' /*, 'import', 'n', 'promise'*/],
extends: [
'standard',
'plugin:prettier/recommended'
// 'eslint:recommended',
'plugin:prettier/recommended',
// 'plugin:import/recommended',
// 'plugin:import/typescript',
// 'plugin:security/recommended',
// 'plugin:@eslint-community/eslint-comments/recommended',
],
plugins: [
'jest'
],
rules: {
settings: {
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx'],
},
'import/resolver': {
typescript: {
project: ['./tsconfig.json'],
},
node: true,
},
},
/* rules: {
//'indent': [ 'error', 2 ],
//'quotes': [ "error", "single"],
// 'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'no-console': ['error'],
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'prettier/prettier': ['error'],
> 'no-console': ['error'],
> 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
> 'prettier/prettier': ['error'],
}, */
rules: {
'no-console': 'error',
camelcase: 'error',
'no-debugger': 'error',
'prettier/prettier': [
'error',
{
htmlWhitespaceSensitivity: 'ignore',
},
],
// import
// 'import/export': 'error',
// 'import/no-deprecated': 'error',
// 'import/no-empty-named-blocks': 'error',
// 'import/no-extraneous-dependencies': 'error',
// 'import/no-mutable-exports': 'error',
// 'import/no-unused-modules': 'error',
// 'import/no-named-as-default': 'error',
// 'import/no-named-as-default-member': 'error',
// 'import/no-amd': 'error',
// 'import/no-commonjs': 'error',
// 'import/no-import-module-exports': 'error',
// 'import/no-nodejs-modules': 'off',
// 'import/unambiguous': 'error',
// 'import/default': 'error',
// 'import/named': 'error',
// 'import/namespace': 'error',
// 'import/no-absolute-path': 'error',
// 'import/no-cycle': 'error',
// 'import/no-dynamic-require': 'error',
// 'import/no-internal-modules': 'off',
// 'import/no-relative-packages': 'error',
// 'import/no-relative-parent-imports': ['error', { ignore: ['@/*'] }],
// 'import/no-self-import': 'error',
// 'import/no-unresolved': 'error',
// 'import/no-useless-path-segments': 'error',
// 'import/no-webpack-loader-syntax': 'error',
// 'import/consistent-type-specifier-style': 'error',
// 'import/exports-last': 'off',
// 'import/extensions': 'error',
// 'import/first': 'error',
// 'import/group-exports': 'off',
// 'import/newline-after-import': 'error',
// 'import/no-anonymous-default-export': 'error',
// 'import/no-default-export': 'error',
// 'import/no-duplicates': 'error',
// 'import/no-named-default': 'error',
// 'import/no-namespace': 'error',
// 'import/no-unassigned-import': 'error',
// 'import/order': [
// 'error',
// {
// groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index', 'object', 'type'],
// 'newlines-between': 'always',
// pathGroups: [
// {
// pattern: '@?*/**',
// group: 'external',
// position: 'after',
// },
// {
// pattern: '@/**',
// group: 'external',
// position: 'after',
// },
// ],
// alphabetize: {
// order: 'asc' /* sort in ascending order. Options: ['ignore', 'asc', 'desc'] */,
// caseInsensitive: true /* ignore case. Options: [true, false] */,
// },
// distinctGroup: true,
// },
// ],
// 'import/prefer-default-export': 'off',
// n
// 'n/handle-callback-err': 'error',
// 'n/no-callback-literal': 'error',
// 'n/no-exports-assign': 'error',
// 'n/no-extraneous-import': 'error',
// 'n/no-extraneous-require': 'error',
// 'n/no-hide-core-modules': 'error',
// 'n/no-missing-import': 'off', // not compatible with typescript
// 'n/no-missing-require': 'error',
// 'n/no-new-require': 'error',
// 'n/no-path-concat': 'error',
// 'n/no-process-exit': 'error',
// 'n/no-unpublished-bin': 'error',
// 'n/no-unpublished-import': 'off', // TODO need to exclude seeds
// 'n/no-unpublished-require': 'error',
// 'n/no-unsupported-features': ['error', { ignores: ['modules'] }],
// 'n/no-unsupported-features/es-builtins': 'error',
// 'n/no-unsupported-features/es-syntax': 'error',
// 'n/no-unsupported-features/node-builtins': 'error',
// 'n/process-exit-as-throw': 'error',
// 'n/shebang': 'error',
// 'n/callback-return': 'error',
// 'n/exports-style': 'error',
// 'n/file-extension-in-import': 'off',
// 'n/global-require': 'error',
// 'n/no-mixed-requires': 'error',
// 'n/no-process-env': 'error',
// 'n/no-restricted-import': 'error',
// 'n/no-restricted-require': 'error',
// 'n/no-sync': 'error',
// 'n/prefer-global/buffer': 'error',
// 'n/prefer-global/console': 'error',
// 'n/prefer-global/process': 'error',
// 'n/prefer-global/text-decoder': 'error',
// 'n/prefer-global/text-encoder': 'error',
// 'n/prefer-global/url': 'error',
// 'n/prefer-global/url-search-params': 'error',
// 'n/prefer-promises/dns': 'error',
// 'n/prefer-promises/fs': 'error',
// promise
// 'promise/catch-or-return': 'error',
// 'promise/no-return-wrap': 'error',
// 'promise/param-names': 'error',
// 'promise/always-return': 'error',
// 'promise/no-native': 'off',
// 'promise/no-nesting': 'warn',
// 'promise/no-promise-in-callback': 'warn',
// 'promise/no-callback-in-promise': 'warn',
// 'promise/avoid-new': 'warn',
// 'promise/no-new-statics': 'error',
// 'promise/no-return-in-finally': 'warn',
// 'promise/valid-params': 'warn',
// 'promise/prefer-await-to-callbacks': 'error',
// 'promise/no-multiple-resolved': 'error',
// eslint comments
// '@eslint-community/eslint-comments/disable-enable-pair': ['error', { allowWholeFile: true }],
// '@eslint-community/eslint-comments/no-restricted-disable': 'error',
// '@eslint-community/eslint-comments/no-use': 'off',
// '@eslint-community/eslint-comments/require-description': 'off',
},
overrides: [
// only for ts files
{
files: ['*.ts', '*.tsx'],
extends: [
// 'plugin:@typescript-eslint/recommended',
// 'plugin:@typescript-eslint/recommended-requiring-type-checking',
// 'plugin:@typescript-eslint/strict',
],
rules: {
// allow explicitly defined dangling promises
// '@typescript-eslint/no-floating-promises': ['error', { ignoreVoid: true }],
'no-void': ['error', { allowAsStatement: true }],
// ignore prefer-regexp-exec rule to allow string.match(regex)
'@typescript-eslint/prefer-regexp-exec': 'off',
// this should not run on ts files: https://github.com/import-js/eslint-plugin-import/issues/2215#issuecomment-911245486
'import/unambiguous': 'off',
// this is not compatible with typeorm, due to joined tables can be null, but are not defined as nullable
'@typescript-eslint/no-unnecessary-condition': 'off',
},
parserOptions: {
tsconfigRootDir: __dirname,
project: ['./tsconfig.json'],
// this is to properly reference the referenced project database without requirement of compiling it
// eslint-disable-next-line camelcase
EXPERIMENTAL_useSourceOfProjectReferenceRedirect: true,
},
},
{
files: ['*.spec.ts'],
plugins: ['jest'],
env: {
jest: true,
},
rules: {
'jest/no-disabled-tests': 'error',
'jest/no-focused-tests': 'error',
'jest/no-identical-title': 'error',
'jest/prefer-to-have-length': 'error',
'jest/valid-expect': 'error',
'@typescript-eslint/unbound-method': 'off',
// 'jest/unbound-method': 'error',
},
},
],
};

View File

@ -14,7 +14,7 @@
"build": "tsc && ./scripts/build.copy.files.sh",
"dev": "nodemon --exec ts-node src/ -e js,ts,gql",
"dev:debug": "nodemon --exec babel-node --inspect=0.0.0.0:9229 src/ -e js,ts,gql",
"lint": "eslint src --config .eslintrc.js",
"lint": "eslint --max-warnings=0 --ext .js,.ts ./src",
"test": "cross-env NODE_ENV=test NODE_OPTIONS=--max-old-space-size=8192 jest --runInBand --coverage --forceExit --detectOpenHandles",
"db:clean": "ts-node src/db/clean.ts",
"db:reset": "yarn run db:clean",
@ -45,7 +45,6 @@
"cheerio": "~1.0.0-rc.3",
"cors": "~2.8.5",
"cross-env": "~7.0.3",
"debug": "~4.1.1",
"dotenv": "~8.2.0",
"express": "^4.17.1",
"graphql": "^14.6.0",
@ -97,27 +96,30 @@
},
"devDependencies": {
"@faker-js/faker": "7.6.0",
"@types/jest": "^29.5.2",
"@types/jest": "^27.0.2",
"@types/node": "^20.2.5",
"@typescript-eslint/eslint-plugin": "^5.57.1",
"@typescript-eslint/parser": "^5.57.1",
"apollo-server-testing": "~2.11.0",
"chai": "~4.2.0",
"cucumber": "~6.0.5",
"eslint": "~6.8.0",
"eslint-config-prettier": "~6.15.0",
"eslint-config-standard": "~14.1.1",
"eslint-plugin-import": "~2.20.2",
"eslint-plugin-jest": "~23.8.2",
"eslint-plugin-node": "~11.1.0",
"eslint-plugin-prettier": "~3.4.1",
"eslint-plugin-promise": "~4.3.1",
"eslint-plugin-standard": "~4.0.1",
"jest": "29.4",
"eslint": "^8.37.0",
"eslint-config-prettier": "^8.8.0",
"eslint-config-standard": "^17.0.0",
"eslint-import-resolver-typescript": "^3.5.4",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jest": "^27.2.1",
"eslint-plugin-n": "^15.7.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-security": "^1.7.1",
"prettier": "^2.8.7",
"jest": "^27.2.4",
"nodemon": "~2.0.2",
"prettier": "~2.3.2",
"rosie": "^2.0.1",
"ts-jest": "^29.1.0",
"ts-jest": "^27.0.5",
"ts-node": "^10.9.1",
"typescript": "^5.0.4"
"typescript": "^4.9.4"
},
"resolutions": {
"**/**/fs-capacitor": "^6.2.0",

View File

@ -15,7 +15,7 @@ if (require.resolve) {
}
// Use Cypress env or process.env
declare var Cypress: any | undefined
declare let Cypress: any | undefined
const env = typeof Cypress !== 'undefined' ? Cypress.env() : process.env // eslint-disable-line no-undef
const environment = {
@ -95,6 +95,7 @@ Object.entries(required).map((entry) => {
if (!entry[1]) {
throw new Error(`ERROR: "${entry[0]}" env variable is missing.`)
}
return entry
})
export default {

View File

@ -1,2 +1,2 @@
const tsNode = require('ts-node');
module.exports = tsNode.register;
const tsNode = require('ts-node')
module.exports = tsNode.register

View File

@ -278,7 +278,7 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
await Promise.all(
categories.map(({ icon, name }, index) => {
Factory.build('category', {
return Factory.build('category', {
id: `cat${index + 1}`,
slug: name,
name,
@ -1112,7 +1112,7 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
const reportAgainstDewey = reports[3]
// report resource first time
await reportAgainstDagobert.relateTo(jennyRostock, 'filed', {
resourceId: 'u7',
reasonCategory: 'discrimination_etc',

View File

@ -2,14 +2,8 @@ import gql from 'graphql-tag'
export const createMessageMutation = () => {
return gql`
mutation (
$roomId: ID!
$content: String!
) {
CreateMessage(
roomId: $roomId
content: $content
) {
mutation ($roomId: ID!, $content: String!) {
CreateMessage(roomId: $roomId, content: $content) {
id
content
}
@ -19,7 +13,7 @@ export const createMessageMutation = () => {
export const messageQuery = () => {
return gql`
query($roomId: ID!) {
query ($roomId: ID!) {
Message(roomId: $roomId) {
_id
id

View File

@ -2,12 +2,8 @@ import gql from 'graphql-tag'
export const createRoomMutation = () => {
return gql`
mutation (
$userId: ID!
) {
CreateRoom(
userId: $userId
) {
mutation ($userId: ID!) {
CreateRoom(userId: $userId) {
id
roomId
}

View File

@ -1,6 +1,6 @@
import cheerio from 'cheerio'
export default (content) => {
export default (content?) => {
if (!content) return []
const $ = cheerio.load(content)
const userIds = $('a.mention[data-mention-id]')

View File

@ -50,7 +50,7 @@ beforeAll(async () => {
context: () => {
return {
user: authenticatedUser,
neode: neode,
neode,
driver,
}
},

View File

@ -1,22 +1,22 @@
import uniqueSlug from './uniqueSlug'
describe('uniqueSlug', () => {
it('slugifies given string', () => {
it('slugifies given string', async () => {
const string = 'Hello World'
const isUnique = jest.fn().mockResolvedValue(true)
expect(uniqueSlug(string, isUnique)).resolves.toEqual('hello-world')
await expect(uniqueSlug(string, isUnique)).resolves.toEqual('hello-world')
})
it('increments slugified string until unique', () => {
it('increments slugified string until unique', async () => {
const string = 'Hello World'
const isUnique = jest.fn().mockResolvedValueOnce(false).mockResolvedValueOnce(true)
expect(uniqueSlug(string, isUnique)).resolves.toEqual('hello-world-1')
await expect(uniqueSlug(string, isUnique)).resolves.toEqual('hello-world-1')
})
it('slugify null string', () => {
it('slugify null string', async () => {
const string = null
const isUnique = jest.fn().mockResolvedValue(true)
expect(uniqueSlug(string, isUnique)).resolves.toEqual('anonymous')
await expect(uniqueSlug(string, isUnique)).resolves.toEqual('anonymous')
})
it('Converts umlaut to a two letter equivalent', async () => {

View File

@ -1,38 +1,29 @@
// 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
declare var Cypress: any | undefined
declare let Cypress: any | undefined
export default {
Image: typeof Cypress !== 'undefined' ? require('./Image') : require('./Image').default,
Badge: typeof Cypress !== 'undefined' ? require('./Badge') : require('./Badge').default,
User: typeof Cypress !== 'undefined' ? require('./User') : require('./User').default,
Group: typeof Cypress !== 'undefined' ? require('./Group') : require('./Group').default,
EmailAddress:
typeof Cypress !== 'undefined'
? require('./EmailAddress')
: require('./EmailAddress').default,
typeof Cypress !== 'undefined' ? require('./EmailAddress') : require('./EmailAddress').default,
UnverifiedEmailAddress:
typeof Cypress !== 'undefined'
? require('./UnverifiedEmailAddress')
: require('./UnverifiedEmailAddress').default,
SocialMedia:
typeof Cypress !== 'undefined'
? require('./SocialMedia')
: require('./SocialMedia').default,
typeof Cypress !== 'undefined' ? require('./SocialMedia') : require('./SocialMedia').default,
Post: typeof Cypress !== 'undefined' ? require('./Post') : require('./Post').default,
Comment:
typeof Cypress !== 'undefined' ? require('./Comment') : require('./Comment').default,
Category:
typeof Cypress !== 'undefined' ? require('./Category') : require('./Category').default,
Comment: typeof Cypress !== 'undefined' ? require('./Comment') : require('./Comment').default,
Category: typeof Cypress !== 'undefined' ? require('./Category') : require('./Category').default,
Tag: typeof Cypress !== 'undefined' ? require('./Tag') : require('./Tag').default,
Location:
typeof Cypress !== 'undefined' ? require('./Location') : require('./Location').default,
Location: typeof Cypress !== 'undefined' ? require('./Location') : require('./Location').default,
Donations:
typeof Cypress !== 'undefined' ? require('./Donations') : require('./Donations').default,
Report: typeof Cypress !== 'undefined' ? require('./Report') : require('./Report').default,
Migration:
typeof Cypress !== 'undefined' ? require('./Migration') : require('./Migration').default,
InviteCode:
typeof Cypress !== 'undefined'
? require('./InviteCode')
: require('./InviteCode').default,
typeof Cypress !== 'undefined' ? require('./InviteCode') : require('./InviteCode').default,
}

View File

@ -170,6 +170,7 @@ describe('mergeImage', () => {
})
})
// eslint-disable-next-line jest/no-disabled-tests
it.skip('automatically creates different image sizes', async () => {
await expect(
mergeImage(post, 'HERO_IMAGE', imageInput, { uploadCallback, deleteCallback }),

View File

@ -34,43 +34,40 @@ afterAll(async () => {
driver.close()
})
describe('Message', () => {
let roomId: string
beforeAll(async () => {
[chattingUser, otherChattingUser, notChattingUser] = await Promise.all([
Factory.build(
'user',
{
id: 'chatting-user',
name: 'Chatting User',
},
),
Factory.build(
'user',
{
id: 'other-chatting-user',
name: 'Other Chatting User',
},
),
Factory.build(
'user',
{
id: 'not-chatting-user',
name: 'Not Chatting User',
},
),
;[chattingUser, otherChattingUser, notChattingUser] = await Promise.all([
Factory.build('user', {
id: 'chatting-user',
name: 'Chatting User',
}),
Factory.build('user', {
id: 'other-chatting-user',
name: 'Other Chatting User',
}),
Factory.build('user', {
id: 'not-chatting-user',
name: 'Not Chatting User',
}),
])
})
describe('create message', () => {
describe('unauthenticated', () => {
it('throws authorization error', async () => {
await expect(mutate({ mutation: createMessageMutation(), variables: {
roomId: 'some-id', content: 'Some bla bla bla', } })).resolves.toMatchObject({
errors: [{ message: 'Not Authorized!' }],
})
await expect(
mutate({
mutation: createMessageMutation(),
variables: {
roomId: 'some-id',
content: 'Some bla bla bla',
},
}),
).resolves.toMatchObject({
errors: [{ message: 'Not Authorized!' }],
})
})
})
@ -81,13 +78,20 @@ describe('Message', () => {
describe('room does not exist', () => {
it('returns null', async () => {
await expect(mutate({ mutation: createMessageMutation(), variables: {
roomId: 'some-id', content: 'Some bla bla bla', } })).resolves.toMatchObject({
errors: undefined,
data: {
CreateMessage: null,
await expect(
mutate({
mutation: createMessageMutation(),
variables: {
roomId: 'some-id',
content: 'Some bla bla bla',
},
})
}),
).resolves.toMatchObject({
errors: undefined,
data: {
CreateMessage: null,
},
})
})
})
@ -104,20 +108,23 @@ describe('Message', () => {
describe('user chats in room', () => {
it('returns the message', async () => {
await expect(mutate({
mutation: createMessageMutation(),
variables: {
roomId,
content: 'Some nice message to other chatting user',
} })).resolves.toMatchObject({
errors: undefined,
data: {
CreateMessage: {
id: expect.any(String),
content: 'Some nice message to other chatting user',
},
await expect(
mutate({
mutation: createMessageMutation(),
variables: {
roomId,
content: 'Some nice message to other chatting user',
},
})
}),
).resolves.toMatchObject({
errors: undefined,
data: {
CreateMessage: {
id: expect.any(String),
content: 'Some nice message to other chatting user',
},
},
})
})
})
@ -125,19 +132,22 @@ describe('Message', () => {
beforeAll(async () => {
authenticatedUser = await notChattingUser.toJson()
})
it('returns null', async () => {
await expect(mutate({
mutation: createMessageMutation(),
variables: {
roomId,
content: 'I have no access to this room!',
} })).resolves.toMatchObject({
errors: undefined,
data: {
CreateMessage: null,
await expect(
mutate({
mutation: createMessageMutation(),
variables: {
roomId,
content: 'I have no access to this room!',
},
})
}),
).resolves.toMatchObject({
errors: undefined,
data: {
CreateMessage: null,
},
})
})
})
})
@ -151,14 +161,17 @@ describe('Message', () => {
})
it('throws authorization error', async () => {
await expect(query({
query: messageQuery(),
variables: {
roomId: 'some-id' }
})).resolves.toMatchObject({
await expect(
query({
query: messageQuery(),
variables: {
roomId: 'some-id',
},
}),
).resolves.toMatchObject({
errors: [{ message: 'Not Authorized!' }],
})
})
})
})
describe('authenticated', () => {
@ -168,12 +181,14 @@ describe('Message', () => {
describe('room does not exists', () => {
it('returns null', async () => {
await expect(query({
query: messageQuery(),
variables: {
roomId: 'some-id'
},
})).resolves.toMatchObject({
await expect(
query({
query: messageQuery(),
variables: {
roomId: 'some-id',
},
}),
).resolves.toMatchObject({
errors: undefined,
data: {
Message: [],
@ -193,15 +208,17 @@ describe('Message', () => {
expect(result).toMatchObject({
errors: undefined,
data: {
Message: [{
id: expect.any(String),
_id: result.data.Message[0].id,
content: 'Some nice message to other chatting user',
senderId: 'chatting-user',
username: 'Chatting User',
avatar: expect.any(String),
date: expect.any(String),
}],
Message: [
{
id: expect.any(String),
_id: result.data.Message[0].id,
content: 'Some nice message to other chatting user',
senderId: 'chatting-user',
username: 'Chatting User',
avatar: expect.any(String),
date: expect.any(String),
},
],
},
})
})
@ -213,7 +230,7 @@ describe('Message', () => {
variables: {
roomId,
content: 'A nice response message to chatting user',
}
},
})
authenticatedUser = await chattingUser.toJson()
await mutate({
@ -221,17 +238,19 @@ describe('Message', () => {
variables: {
roomId,
content: 'And another nice message to other chatting user',
}
})
})
it('returns the messages', async () => {
await expect(query({
query: messageQuery(),
variables: {
roomId,
},
})).resolves.toMatchObject({
})
})
it('returns the messages', async () => {
await expect(
query({
query: messageQuery(),
variables: {
roomId,
},
}),
).resolves.toMatchObject({
errors: undefined,
data: {
Message: expect.arrayContaining([
@ -263,7 +282,7 @@ describe('Message', () => {
},
})
})
})
})
})
describe('room exists, authenticated user not in room', () => {
@ -272,19 +291,21 @@ describe('Message', () => {
})
it('returns null', async () => {
await expect(query({
query: messageQuery(),
variables: {
roomId,
},
})).resolves.toMatchObject({
await expect(
query({
query: messageQuery(),
variables: {
roomId,
},
}),
).resolves.toMatchObject({
errors: undefined,
data: {
Message: [],
},
})
})
})
})
})
})
})

View File

@ -25,7 +25,9 @@ export default {
Mutation: {
CreateMessage: async (_parent, params, context, _resolveInfo) => {
const { roomId, content } = params
const { user: { id: currentUserId } } = context
const {
user: { id: currentUserId },
} = context
const session = context.driver.session()
const writeTxResultPromise = session.writeTransaction(async (transaction) => {
const createMessageCypher = `
@ -37,13 +39,14 @@ export default {
})-[:INSIDE]->(room)
RETURN message { .* }
`
const createMessageTxResponse = await transaction.run(
createMessageCypher,
{ currentUserId, roomId, content }
)
const createMessageTxResponse = await transaction.run(createMessageCypher, {
currentUserId,
roomId,
content,
})
const [message] = await createMessageTxResponse.records.map((record) =>
record.get('message'),
)
record.get('message'),
)
return message
})
try {
@ -53,7 +56,7 @@ export default {
throw new Error(error)
} finally {
session.close()
}
}
},
},
Message: {
@ -61,7 +64,7 @@ export default {
hasOne: {
author: '<-[:CREATED]-(related:User)',
room: '-[:INSIDE]->(related:Room)',
}
},
}),
}
},
}

View File

@ -238,7 +238,7 @@ describe('given some notifications', () => {
variables: { ...variables, read: false },
})
await expect(response).toMatchObject(expected)
await expect(response.data.notifications.length).toEqual(2) // double-check
await expect(response.data.notifications).toHaveLength(2) // double-check
})
describe('if a resource gets deleted', () => {

View File

@ -907,6 +907,7 @@ describe('UpdatePost', () => {
})
})
// eslint-disable-next-line jest/no-disabled-tests
describe.skip('params.image', () => {
describe('is object', () => {
beforeEach(() => {

View File

@ -28,7 +28,7 @@ export default {
},
SignupVerification: async (_parent, args, context) => {
const { termsAndConditionsAgreedVersion } = args
const regEx = new RegExp(/^[0-9]+\.[0-9]+\.[0-9]+$/g)
const regEx = /^[0-9]+\.[0-9]+\.[0-9]+$/g
if (!regEx.test(termsAndConditionsAgreedVersion)) {
throw new UserInputError('Invalid version format!')
}

View File

@ -728,7 +728,7 @@ describe('file a report on a resource', () => {
describe('unauthenticated', () => {
it('throws authorization error', async () => {
authenticatedUser = null
expect(query({ query: reportsQuery })).resolves.toMatchObject({
await expect(query({ query: reportsQuery })).resolves.toMatchObject({
data: { reports: null },
errors: [{ message: 'Not Authorized!' }],
})
@ -738,7 +738,7 @@ describe('file a report on a resource', () => {
describe('authenticated', () => {
it('role "user" gets no reports', async () => {
authenticatedUser = await currentUser.toJson()
expect(query({ query: reportsQuery })).resolves.toMatchObject({
await expect(query({ query: reportsQuery })).resolves.toMatchObject({
data: { reports: null },
errors: [{ message: 'Not Authorized!' }],
})

View File

@ -35,56 +35,55 @@ afterAll(async () => {
describe('Room', () => {
beforeAll(async () => {
[chattingUser, otherChattingUser, notChattingUser] = await Promise.all([
Factory.build(
'user',
{
id: 'chatting-user',
name: 'Chatting User',
},
),
Factory.build(
'user',
{
id: 'other-chatting-user',
name: 'Other Chatting User',
},
),
Factory.build(
'user',
{
id: 'not-chatting-user',
name: 'Not Chatting User',
},
),
;[chattingUser, otherChattingUser, notChattingUser] = await Promise.all([
Factory.build('user', {
id: 'chatting-user',
name: 'Chatting User',
}),
Factory.build('user', {
id: 'other-chatting-user',
name: 'Other Chatting User',
}),
Factory.build('user', {
id: 'not-chatting-user',
name: 'Not Chatting User',
}),
])
})
describe('create room', () => {
describe('unauthenticated', () => {
it('throws authorization error', async () => {
await expect(mutate({ mutation: createRoomMutation(), variables: {
userId: 'some-id' } })).resolves.toMatchObject({
errors: [{ message: 'Not Authorized!' }],
})
await expect(
mutate({
mutation: createRoomMutation(),
variables: {
userId: 'some-id',
},
}),
).resolves.toMatchObject({
errors: [{ message: 'Not Authorized!' }],
})
})
})
describe('authenticated', () => {
let roomId: string
beforeAll(async () => {
authenticatedUser = await chattingUser.toJson()
})
describe('user id does not exist', () => {
it('returns null', async () => {
await expect(mutate({
mutation: createRoomMutation(),
variables: {
userId: 'not-existing-user',
},
})).resolves.toMatchObject({
await expect(
mutate({
mutation: createRoomMutation(),
variables: {
userId: 'not-existing-user',
},
}),
).resolves.toMatchObject({
errors: undefined,
data: {
CreateRoom: null,
@ -92,7 +91,7 @@ describe('Room', () => {
})
})
})
describe('user id exists', () => {
it('returns the id of the room', async () => {
const result = await mutate({
@ -116,12 +115,14 @@ describe('Room', () => {
describe('create room with same user id', () => {
it('returns the id of the room', async () => {
await expect(mutate({
mutation: createRoomMutation(),
variables: {
userId: 'other-chatting-user',
},
})).resolves.toMatchObject({
await expect(
mutate({
mutation: createRoomMutation(),
variables: {
userId: 'other-chatting-user',
},
}),
).resolves.toMatchObject({
errors: undefined,
data: {
CreateRoom: {
@ -130,7 +131,7 @@ describe('Room', () => {
},
})
})
})
})
})
})
@ -139,11 +140,11 @@ describe('Room', () => {
beforeAll(() => {
authenticatedUser = null
})
it('throws authorization error', async () => {
await expect(query({ query: roomQuery() })).resolves.toMatchObject({
errors: [{ message: 'Not Authorized!' }],
})
errors: [{ message: 'Not Authorized!' }],
})
})
})
@ -194,7 +195,7 @@ describe('Room', () => {
})
it('returns the room', async () => {
const result = await query({ query: roomQuery() })
const result = await query({ query: roomQuery() })
expect(result).toMatchObject({
errors: undefined,
data: {
@ -241,7 +242,7 @@ describe('Room', () => {
},
})
})
})
})
})
})
})

View File

@ -3,7 +3,7 @@ import Resolver from './helpers/Resolver'
export default {
Query: {
Room: async (object, params, context, resolveInfo) => {
Room: async (object, params, context, resolveInfo) => {
if (!params.filter) params.filter = {}
params.filter.users_some = {
id: context.user.id,
@ -25,7 +25,9 @@ export default {
Mutation: {
CreateRoom: async (_parent, params, context, _resolveInfo) => {
const { userId } = params
const { user: { id: currentUserId } } = context
const {
user: { id: currentUserId },
} = context
const session = context.driver.session()
const writeTxResultPromise = session.writeTransaction(async (transaction) => {
const createRoomCypher = `
@ -37,13 +39,11 @@ export default {
room.id = apoc.create.uuid()
RETURN room { .* }
`
const createRommTxResponse = await transaction.run(
createRoomCypher,
{ userId, currentUserId }
)
const [room] = await createRommTxResponse.records.map((record) =>
record.get('room'),
)
const createRommTxResponse = await transaction.run(createRoomCypher, {
userId,
currentUserId,
})
const [room] = await createRommTxResponse.records.map((record) => record.get('room'))
return room
})
try {
@ -56,14 +56,14 @@ export default {
throw new Error(error)
} finally {
session.close()
}
}
},
},
Room: {
...Resolver('Room', {
hasMany: {
users: '<-[:CHATS_IN]-(related:User)',
}
},
}),
}
},
}

View File

@ -590,7 +590,7 @@ describe('save category settings', () => {
beforeEach(async () => {
await Promise.all(
categories.map(({ icon, name }, index) => {
Factory.build('category', {
return Factory.build('category', {
id: `cat${index + 1}`,
slug: name,
name,

View File

@ -144,7 +144,7 @@ export default {
params.locationName = params.locationName === '' ? null : params.locationName
const { termsAndConditionsAgreedVersion } = params
if (termsAndConditionsAgreedVersion) {
const regEx = new RegExp(/^[0-9]+\.[0-9]+\.[0-9]+$/g)
const regEx = /^[0-9]+\.[0-9]+\.[0-9]+$/g
if (!regEx.test(termsAndConditionsAgreedVersion)) {
throw new ForbiddenError('Invalid version format!')
}

View File

@ -106,6 +106,4 @@
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
},
"include": ["./src/**/*"],
"exclude": ["./src/**/*.spec.ts"]
}

File diff suppressed because it is too large Load Diff

View File

@ -15,7 +15,7 @@
/* globals Cypress cy */
import "cypress-file-upload";
import { GraphQLClient, request } from 'graphql-request'
import CONFIG from '../../backend/build/config'
import CONFIG from '../../backend/build/src/config'
const authenticatedHeaders = (variables) => {
const mutation = `

View File

@ -1,5 +1,5 @@
import Factory from '../../backend/build/db/factories'
import { getNeode } from '../../backend/build/db/neo4j'
import Factory from '../../backend/build/src/db/factories'
import { getNeode } from '../../backend/build/src/db/neo4j'
const neodeInstance = getNeode()

View File

@ -1,5 +1,5 @@
import { Given } from "@badeball/cypress-cucumber-preprocessor";
import encode from '../../../../backend/build/jwt/encode'
import encode from '../../../../backend/build/src/jwt/encode'
Given("I am logged in as {string}", slug => {
cy.neode()