mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Query groups by 'Group' resolver via 'slug' and test it
This commit is contained in:
parent
b3a0d88a46
commit
36f6fee8be
@ -123,13 +123,7 @@ export const groupQuery = gql`
|
|||||||
query (
|
query (
|
||||||
$isMember: Boolean
|
$isMember: Boolean
|
||||||
$id: ID
|
$id: ID
|
||||||
$name: String
|
|
||||||
$slug: String
|
$slug: String
|
||||||
$createdAt: String
|
|
||||||
$updatedAt: String
|
|
||||||
$about: String
|
|
||||||
$description: String
|
|
||||||
$locationName: String
|
|
||||||
$first: Int
|
$first: Int
|
||||||
$offset: Int
|
$offset: Int
|
||||||
$orderBy: [_GroupOrdering]
|
$orderBy: [_GroupOrdering]
|
||||||
@ -138,13 +132,7 @@ export const groupQuery = gql`
|
|||||||
Group(
|
Group(
|
||||||
isMember: $isMember
|
isMember: $isMember
|
||||||
id: $id
|
id: $id
|
||||||
name: $name
|
|
||||||
slug: $slug
|
slug: $slug
|
||||||
createdAt: $createdAt
|
|
||||||
updatedAt: $updatedAt
|
|
||||||
about: $about
|
|
||||||
description: $description
|
|
||||||
locationName: $locationName
|
|
||||||
first: $first
|
first: $first
|
||||||
offset: $offset
|
offset: $offset
|
||||||
orderBy: $orderBy
|
orderBy: $orderBy
|
||||||
|
|||||||
@ -10,14 +10,26 @@ import { mergeImage } from './images/images'
|
|||||||
export default {
|
export default {
|
||||||
Query: {
|
Query: {
|
||||||
Group: async (_object, params, context, _resolveInfo) => {
|
Group: async (_object, params, context, _resolveInfo) => {
|
||||||
const { id: groupId, isMember } = params
|
const { isMember, id, slug } = params
|
||||||
|
const matchParams = { id, slug }
|
||||||
|
Object.keys(matchParams).forEach((key) => {
|
||||||
|
if ([undefined, null].includes(matchParams[key])) {
|
||||||
|
delete matchParams[key]
|
||||||
|
}
|
||||||
|
})
|
||||||
const session = context.driver.session()
|
const session = context.driver.session()
|
||||||
const readTxResultPromise = session.readTransaction(async (txc) => {
|
const readTxResultPromise = session.readTransaction(async (txc) => {
|
||||||
const groupIdCypher = groupId ? ` {id: "${groupId}"}` : ''
|
const matchParamsEntries = Object.entries(matchParams)
|
||||||
|
let groupMatchParamsCypher = ''
|
||||||
|
matchParamsEntries.forEach((ele, index) => {
|
||||||
|
groupMatchParamsCypher += index === 0 ? ' {' : ''
|
||||||
|
groupMatchParamsCypher += `${ele[0]}: "${ele[1]}"`
|
||||||
|
groupMatchParamsCypher += index < matchParamsEntries.length - 1 ? ', ' : '}'
|
||||||
|
})
|
||||||
let groupCypher
|
let groupCypher
|
||||||
if (isMember === true) {
|
if (isMember === true) {
|
||||||
groupCypher = `
|
groupCypher = `
|
||||||
MATCH (:User {id: $userId})-[membership:MEMBER_OF]->(group:Group${groupIdCypher})
|
MATCH (:User {id: $userId})-[membership:MEMBER_OF]->(group:Group${groupMatchParamsCypher})
|
||||||
WITH group, membership
|
WITH group, membership
|
||||||
WHERE (group.groupType IN ['public', 'closed']) OR (group.groupType = 'hidden' AND membership.role IN ['usual', 'admin', 'owner'])
|
WHERE (group.groupType IN ['public', 'closed']) OR (group.groupType = 'hidden' AND membership.role IN ['usual', 'admin', 'owner'])
|
||||||
RETURN group {.*, myRole: membership.role}
|
RETURN group {.*, myRole: membership.role}
|
||||||
@ -25,7 +37,7 @@ export default {
|
|||||||
} else {
|
} else {
|
||||||
if (isMember === false) {
|
if (isMember === false) {
|
||||||
groupCypher = `
|
groupCypher = `
|
||||||
MATCH (group:Group${groupIdCypher})
|
MATCH (group:Group${groupMatchParamsCypher})
|
||||||
WHERE (NOT (:User {id: $userId})-[:MEMBER_OF]->(group))
|
WHERE (NOT (:User {id: $userId})-[:MEMBER_OF]->(group))
|
||||||
WITH group
|
WITH group
|
||||||
WHERE group.groupType IN ['public', 'closed']
|
WHERE group.groupType IN ['public', 'closed']
|
||||||
@ -33,7 +45,7 @@ export default {
|
|||||||
`
|
`
|
||||||
} else {
|
} else {
|
||||||
groupCypher = `
|
groupCypher = `
|
||||||
MATCH (group:Group${groupIdCypher})
|
MATCH (group:Group${groupMatchParamsCypher})
|
||||||
OPTIONAL MATCH (:User {id: $userId})-[membership:MEMBER_OF]->(group)
|
OPTIONAL MATCH (:User {id: $userId})-[membership:MEMBER_OF]->(group)
|
||||||
WITH group, membership
|
WITH group, membership
|
||||||
WHERE (group.groupType IN ['public', 'closed']) OR (group.groupType = 'hidden' AND membership.role IN ['usual', 'admin', 'owner'])
|
WHERE (group.groupType IN ['public', 'closed']) OR (group.groupType = 'hidden' AND membership.role IN ['usual', 'admin', 'owner'])
|
||||||
|
|||||||
@ -503,6 +503,72 @@ describe('in mode', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('with given slug', () => {
|
||||||
|
describe("slug = 'the-best-group'", () => {
|
||||||
|
it('finds only the listed group with this slug', async () => {
|
||||||
|
const result = await query({
|
||||||
|
query: groupQuery,
|
||||||
|
variables: { slug: 'the-best-group' },
|
||||||
|
})
|
||||||
|
expect(result).toMatchObject({
|
||||||
|
data: {
|
||||||
|
Group: [
|
||||||
|
expect.objectContaining({
|
||||||
|
id: 'my-group',
|
||||||
|
slug: 'the-best-group',
|
||||||
|
myRole: 'owner',
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
errors: undefined,
|
||||||
|
})
|
||||||
|
expect(result.data.Group.length).toBe(1)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("slug = 'third-investigative-journalism-group'", () => {
|
||||||
|
it("finds only the hidden group where I'm 'usual' member", async () => {
|
||||||
|
const result = await query({
|
||||||
|
query: groupQuery,
|
||||||
|
variables: { slug: 'third-investigative-journalism-group' },
|
||||||
|
})
|
||||||
|
expect(result).toMatchObject({
|
||||||
|
data: {
|
||||||
|
Group: expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: 'third-hidden-group',
|
||||||
|
slug: 'third-investigative-journalism-group',
|
||||||
|
myRole: 'usual',
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
},
|
||||||
|
errors: undefined,
|
||||||
|
})
|
||||||
|
expect(result.data.Group.length).toBe(1)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("slug = 'second-investigative-journalism-group'", () => {
|
||||||
|
it("finds no hidden group where I'm 'pending' member", async () => {
|
||||||
|
const result = await query({
|
||||||
|
query: groupQuery,
|
||||||
|
variables: { slug: 'second-investigative-journalism-group' },
|
||||||
|
})
|
||||||
|
expect(result.data.Group.length).toBe(0)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("slug = 'investigative-journalism-group'", () => {
|
||||||
|
it("finds no hidden group where I'm not(!) a member at all", async () => {
|
||||||
|
const result = await query({
|
||||||
|
query: groupQuery,
|
||||||
|
variables: { slug: 'investigative-journalism-group' },
|
||||||
|
})
|
||||||
|
expect(result.data.Group.length).toBe(0)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('isMember = true', () => {
|
describe('isMember = true', () => {
|
||||||
it('finds only listed groups where user is member', async () => {
|
it('finds only listed groups where user is member', async () => {
|
||||||
const result = await query({ query: groupQuery, variables: { isMember: true } })
|
const result = await query({ query: groupQuery, variables: { isMember: true } })
|
||||||
|
|||||||
@ -61,16 +61,7 @@ type Query {
|
|||||||
Group(
|
Group(
|
||||||
isMember: Boolean # if 'undefined' or 'null' then get all groups
|
isMember: Boolean # if 'undefined' or 'null' then get all groups
|
||||||
id: ID
|
id: ID
|
||||||
name: String
|
|
||||||
slug: String
|
slug: String
|
||||||
createdAt: String
|
|
||||||
updatedAt: String
|
|
||||||
about: String
|
|
||||||
description: String
|
|
||||||
# groupType: GroupType # test this
|
|
||||||
# actionRadius: GroupActionRadius # test this
|
|
||||||
# avatar: ImageInput # test this
|
|
||||||
locationName: String
|
|
||||||
first: Int
|
first: Int
|
||||||
offset: Int
|
offset: Int
|
||||||
orderBy: [_GroupOrdering]
|
orderBy: [_GroupOrdering]
|
||||||
|
|||||||
@ -123,13 +123,7 @@ export const groupQuery = gql`
|
|||||||
query (
|
query (
|
||||||
$isMember: Boolean
|
$isMember: Boolean
|
||||||
$id: ID
|
$id: ID
|
||||||
$name: String
|
|
||||||
$slug: String
|
$slug: String
|
||||||
$createdAt: String
|
|
||||||
$updatedAt: String
|
|
||||||
$about: String
|
|
||||||
$description: String
|
|
||||||
$locationName: String
|
|
||||||
$first: Int
|
$first: Int
|
||||||
$offset: Int
|
$offset: Int
|
||||||
$orderBy: [_GroupOrdering]
|
$orderBy: [_GroupOrdering]
|
||||||
@ -138,13 +132,7 @@ export const groupQuery = gql`
|
|||||||
Group(
|
Group(
|
||||||
isMember: $isMember
|
isMember: $isMember
|
||||||
id: $id
|
id: $id
|
||||||
name: $name
|
|
||||||
slug: $slug
|
slug: $slug
|
||||||
createdAt: $createdAt
|
|
||||||
updatedAt: $updatedAt
|
|
||||||
about: $about
|
|
||||||
description: $description
|
|
||||||
locationName: $locationName
|
|
||||||
first: $first
|
first: $first
|
||||||
offset: $offset
|
offset: $offset
|
||||||
orderBy: $orderBy
|
orderBy: $orderBy
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user