diff --git a/backend/src/schema/resolvers/posts.js b/backend/src/schema/resolvers/posts.js index 4e7f21c40..4a11d98c4 100644 --- a/backend/src/schema/resolvers/posts.js +++ b/backend/src/schema/resolvers/posts.js @@ -153,7 +153,7 @@ export default { updatePostCypher += ` MATCH (user:User {id: $userId}) WHERE user.role = 'admin' - MERGE (user)-[:PINNED]->(post) + MERGE (user)-[:PINNED {createdAt: toString(datetime())}]->(post) WITH post ` } diff --git a/backend/src/schema/resolvers/posts.spec.js b/backend/src/schema/resolvers/posts.spec.js index f41d442a4..d23bf23f0 100644 --- a/backend/src/schema/resolvers/posts.spec.js +++ b/backend/src/schema/resolvers/posts.spec.js @@ -725,20 +725,29 @@ describe('UpdatePost', () => { }) describe('removes other pinned post', () => { + let pinnedPost beforeEach(async () => { await factory.create('Post', { id: 'only-pinned-post', author: admin, }) - }) - - it('leaves only one pinned post at a time', async () => { - expect.assertions(1) await mutate({ mutation: updatePostMutation, variables }) variables = { ...variables, id: 'only-pinned-post' } await mutate({ mutation: updatePostMutation, variables }) - const pinnedPosts = await neode.cypher(`MATCH ()-[:PINNED]->(post:Post) RETURN post`) - expect(pinnedPosts.records).toHaveLength(1) + pinnedPost = await neode.cypher( + `MATCH ()-[relationship:PINNED]->(post:Post) RETURN post, relationship`, + ) + }) + + it('leaves only one pinned post at a time', async () => { + expect(pinnedPost.records).toHaveLength(1) + }) + + it('leaves only one pinned post at a time', async () => { + const [pinnedPostCreatedAt] = pinnedPost.records.map( + record => record.get('relationship').properties.createdAt, + ) + expect(pinnedPostCreatedAt).toEqual(expect.any(String)) }) }) })