From 928f9027d3d7b418b6d11adf9bb0321191143cfe Mon Sep 17 00:00:00 2001 From: Ramon Wenger Date: Thu, 27 Jan 2022 17:34:45 +0100 Subject: [PATCH] Clean up code, make Query and Mutation more standard compliant --- client/cypress/fixtures/mocks.js | 6 +- .../frontend/objectives-visibility.spec.js | 3 +- .../frontend/portfolio/project-page.spec.js | 6 +- .../frontend/rooms/article-page.spec.js | 4 +- .../frontend/rooms/rooms-page.spec.js | 3 +- .../content-block-form/ContentElement.vue | 1 - .../portfolio/NewProjectEntryWizard.vue | 12 +- .../school-class/ClassSelectionWidget.vue | 3 +- client/src/graphql/cache.js | 49 +++-- client/src/graphql/gql/queries/oldClasses.gql | 8 +- .../src/mixins/update-project-share-state.js | 11 +- client/src/pages/article.vue | 11 +- client/src/pages/createContentBlock.vue | 3 - server/api/schema.py | 6 +- server/schema.graphql | 202 +++++++++--------- server/users/schema.py | 4 +- 16 files changed, 164 insertions(+), 168 deletions(-) diff --git a/client/cypress/fixtures/mocks.js b/client/cypress/fixtures/mocks.js index 2785396c..33f39295 100644 --- a/client/cypress/fixtures/mocks.js +++ b/client/cypress/fixtures/mocks.js @@ -1,5 +1,7 @@ +export const SELECTED_CLASS_ID = 987; +export const SELECTED_CLASS_ID_ENCODED = btoa(`SchoolClassNode:${SELECTED_CLASS_ID}`); const selectedClass = { - id: btoa('SchoolClassNode:selectedClassId'), + id: SELECTED_CLASS_ID_ENCODED, name: 'Moordale', readOnly: false, code: 'XXXX', @@ -100,7 +102,7 @@ export default { appearance: 'blue', description: 'A Room description', schoolClass: { - id: 'selectedClassId', + id: SELECTED_CLASS_ID_ENCODED, }, }), RoomEntryNode: () => ({ diff --git a/client/cypress/integration/frontend/objectives-visibility.spec.js b/client/cypress/integration/frontend/objectives-visibility.spec.js index 43c6ebb8..57b032da 100644 --- a/client/cypress/integration/frontend/objectives-visibility.spec.js +++ b/client/cypress/integration/frontend/objectives-visibility.spec.js @@ -79,7 +79,8 @@ describe('Objective Visibility', () => { }); }); - it('should display the correct objectives', () => { + //todo: finish writing this test, this does nothing + it.skip('should display the correct objectives', () => { cy.fakeLogin('rachel.green', 'test'); cy.visit('/module/lohn-und-budget'); diff --git a/client/cypress/integration/frontend/portfolio/project-page.spec.js b/client/cypress/integration/frontend/portfolio/project-page.spec.js index 2a03aa3e..0a211c27 100644 --- a/client/cypress/integration/frontend/portfolio/project-page.spec.js +++ b/client/cypress/integration/frontend/portfolio/project-page.spec.js @@ -95,10 +95,8 @@ describe('Project Page', () => { beforeEach(() => { cy.setup(); - cy.task('getSchema').then(schema => { - cy.mockGraphqlOps({ - operations, - }); + cy.mockGraphqlOps({ + operations, }); }); diff --git a/client/cypress/integration/frontend/rooms/article-page.spec.js b/client/cypress/integration/frontend/rooms/article-page.spec.js index f8a596d4..3830ed0a 100644 --- a/client/cypress/integration/frontend/rooms/article-page.spec.js +++ b/client/cypress/integration/frontend/rooms/article-page.spec.js @@ -6,9 +6,7 @@ describe('Article page', () => { slug, id: 'room-entry-id', title: 'Some Room Entry, yay!', - comments: { - edges: [], - }, + comments: [], }; const operations = { diff --git a/client/cypress/integration/frontend/rooms/rooms-page.spec.js b/client/cypress/integration/frontend/rooms/rooms-page.spec.js index a83dc9a5..8c10ece2 100644 --- a/client/cypress/integration/frontend/rooms/rooms-page.spec.js +++ b/client/cypress/integration/frontend/rooms/rooms-page.spec.js @@ -1,4 +1,5 @@ import {getMinimalMe} from '../../../support/helpers'; +import {SELECTED_CLASS_ID_ENCODED} from '../../../fixtures/mocks'; describe('The Rooms Page', () => { const getOperations = (isTeacher) => ({ @@ -6,7 +7,7 @@ describe('The Rooms Page', () => { RoomsQuery: { rooms: [{ schoolClass: { - id: btoa('SchoolClassNode:selectedClassId'), + id: SELECTED_CLASS_ID_ENCODED, }, }], }, diff --git a/client/src/components/content-block-form/ContentElement.vue b/client/src/components/content-block-form/ContentElement.vue index 04138aaf..4d1836b7 100644 --- a/client/src/components/content-block-form/ContentElement.vue +++ b/client/src/components/content-block-form/ContentElement.vue @@ -163,7 +163,6 @@ this._updateProperty(value, 'assignment'); }, changeType({type, convertToList}, value) { - console.log(type, value, convertToList); let el = { type: type, value: Object.assign({}, value), diff --git a/client/src/components/portfolio/NewProjectEntryWizard.vue b/client/src/components/portfolio/NewProjectEntryWizard.vue index 98ff40a0..457f7e18 100644 --- a/client/src/components/portfolio/NewProjectEntryWizard.vue +++ b/client/src/components/portfolio/NewProjectEntryWizard.vue @@ -49,9 +49,15 @@ update: (store, {data: {addProjectEntry: {projectEntry}}}) => { const query = PROJECT_QUERY; const variables = {slug: this.slug}; - const data = store.readQuery({query, variables}); - if (data.project && data.project.entries) { - data.project.entries.push(projectEntry); + const {project} = store.readQuery({query, variables}); + if (project) { + const entries = [...project.entries, projectEntry]; + const data = { + project: { + ...project, + entries + } + }; store.writeQuery({query, variables, data}); } } diff --git a/client/src/components/school-class/ClassSelectionWidget.vue b/client/src/components/school-class/ClassSelectionWidget.vue index 4e881563..bb138f1c 100644 --- a/client/src/components/school-class/ClassSelectionWidget.vue +++ b/client/src/components/school-class/ClassSelectionWidget.vue @@ -112,8 +112,7 @@