From 06cb0b7fec3d0595c23c44932ec00db75bdadfed Mon Sep 17 00:00:00 2001 From: Hikaru Watanabe Date: Fri, 5 Mar 2021 20:04:13 +0900 Subject: [PATCH] Fix Inquiry tests --- tests/e2e/specs/pattern/Inquiry.js | 163 ++++++++++++++++++++++++++- tests/e2e/specs/scenario/Inquiry.js | 168 +++++++++++++++++++++++++++- 2 files changed, 324 insertions(+), 7 deletions(-) diff --git a/tests/e2e/specs/pattern/Inquiry.js b/tests/e2e/specs/pattern/Inquiry.js index 613723d98..19c9590bb 100644 --- a/tests/e2e/specs/pattern/Inquiry.js +++ b/tests/e2e/specs/pattern/Inquiry.js @@ -15,6 +15,141 @@ const getMessages = () => { }); }; +const expectedResponseShortExt = { + ext_03: { + key: '1', + label: 'radio1', + }, + ext_04: { + key: '1', + label: 'select1', + }, + ext_05: [ + { + key: '1', + label: 'check1', + }, + { + key: '3', + label: 'check3', + }, + ], + ext_11: [ + { + ROW: { + key: 'col1', + label: 'COLUMN_1' + }, + COL: { + key: 'row1', + label: 'ROW_1' + } + }, + { + ROW: { + key: 'col2', + label: 'COLUMN_2' + }, + COL: { + key: 'row2', + label: 'ROW_2' + } + }, + { + ROW: { + key: 'col3', + label: 'COLUMN_3' + }, + COL: { + key: 'row3', + label: 'ROW_3' + } + }, + ], + ext_12: [ + { + ROW: { + key: 'col1', + label: 'COLUMN_1' + }, + COL: [ + { + key: 'row1', + label: 'ROW_1' + } + ] + }, + { + ROW: { + key: 'col2', + label: 'COLUMN_2' + }, + COL: [ + { + key: 'row1', + label: 'ROW_1' + }, + { + key: 'row2', + label: 'ROW_2' + }, + ] + }, + { + ROW: { + key: 'col3', + label: 'COLUMN_3' + }, + COL: [ + { + key: 'row1', + label: 'ROW_1' + }, + { + key: 'row2', + label: 'ROW_2' + }, + { + key: 'row3', + label: 'ROW_3' + } + ] + }, + ], +}; +const sendMessageShortExt = () => { + /** @type {import('../../../../generated/services/InquiriesService').InquiriesService.postInquiriesServiceRcmsApi1Inquiry1MessagesSendRequest} */ + const requestData = { + requestBody: { + name: 'Inquiry Test', + from_mail: 'email@example.com', + body: 'test', + inquiry_category_id: 1, + ext_01: 'string1', + ext_03: '1', + ext_04: '1', + ext_05: ['1', '3'], + ext_11: { + col1: 'row1', + col2: 'row2', + col3: 'row3', + }, + ext_12: { + col1: ['row1'], + col2: ['row1', 'row2'], + col3: ['row1', 'row2', 'row3'], + }, + validate_only: false, + }, + }; + return executeRequest({ + cy, + query: 'inquiry send', + requestData, + timeout: 15000, + }); +}; + const sendMessageWithoutRequiredTargetCols = [ 'inquiry_category_id', 'ext_01', @@ -135,6 +270,27 @@ const sendMessageMalformed = ({ targetCol }) => { describe('Inquiry', () => { + it('send message with short ext', async () => { + login(); + const insertRes = await sendMessageShortExt(); + const addedId = insertRes.id; + + const getMessageBy = async id => { + try { + return (await getMessages()).list.find( + msg => msg.inquiry_bn_id === id + ); + } catch(e) { + throw Error(`the created message is not found.\nid: ${id}\n${e}`) + } + }; + const sentMessage = await getMessageBy(addedId); + expect(sentMessage).to.exist; + Object.keys(expectedResponseShortExt).forEach(key => { + expect(sentMessage[key], key).to.deep.equal(expectedResponseShortExt[key]); + }); + }); + sendMessageWithoutRequiredTargetCols.forEach(target => { it('send message without required ' + target + ' -> error', async () => { login(); @@ -143,7 +299,9 @@ describe('Inquiry', () => { errorResponse = JSON.parse(e.message); }) expect(errorResponse.status).to.equal(400, target); - expect(errorResponse.body.errors[0]).to.include('Required property missing: ' + target); + // expect(errorResponse.body.errors[0]).to.include('Required property missing: ' + target); + expect(errorResponse.body.errors[0].code).to.equal('required'); + }); }) @@ -155,7 +313,8 @@ describe('Inquiry', () => { errorResponse = JSON.parse(e.message); }); expect(errorResponse.status).to.equal(400); - expect(errorResponse.body.errors[0]).to.include('properties:'+target, target); + // expect(errorResponse.body.errors[0]).to.include('properties:'+target, target); + expect(errorResponse.body.errors[0].code).to.equal('invalid'); }); }); diff --git a/tests/e2e/specs/scenario/Inquiry.js b/tests/e2e/specs/scenario/Inquiry.js index 8fcaf752e..e893176d1 100644 --- a/tests/e2e/specs/scenario/Inquiry.js +++ b/tests/e2e/specs/scenario/Inquiry.js @@ -35,6 +35,89 @@ const getFormById = ({ inquiryId }) => { requestData, }); }; + +const requestBodySendExt11 = [ + { + "ROW": { + "key": "col1", + "label": "COLUMN_1" + }, + "COL": { + "key": "row1", + "label": "ROW_1" + } + }, + { + "ROW": { + "key": "col2", + "label": "COLUMN_2" + }, + "COL": { + "key": "row2", + "label": "ROW_2" + } + }, + { + "ROW": { + "key": "col3", + "label": "COLUMN_3" + }, + "COL": { + "key": "row3", + "label": "ROW_3" + } + }, +]; +const requestBodySendExt12 = [ + { + "ROW": { + "key": "col1", + "label": "COLUMN_1" + }, + "COL": [ + { + "key": "row1", + "label": "ROW_1" + } + ] + }, + { + "ROW": { + "key": "col2", + "label": "COLUMN_2" + }, + "COL": [ + { + "key": "row1", + "label": "ROW_1" + }, + { + "key": "row2", + "label": "ROW_2" + }, + ] + }, + { + "ROW": { + "key": "col3", + "label": "COLUMN_3" + }, + "COL": [ + { + "key": "row1", + "label": "ROW_1" + }, + { + "key": "row2", + "label": "ROW_2" + }, + { + "key": "row3", + "label": "ROW_3" + } + ] + }, +]; const sendMessage = ({ file }) => { /** @type {import('../../../../generated/services/InquiriesService').InquiriesService.postInquiriesServiceRcmsApi1Inquiry1MessagesSendRequest} */ const requestData = { @@ -78,6 +161,8 @@ const sendMessage = ({ file }) => { text: 'Text1', }, ext_10: '2020-04-23', + ext_11: requestBodySendExt11, + ext_12: requestBodySendExt12, validate_only: false, }, }; @@ -88,15 +173,82 @@ const sendMessage = ({ file }) => { timeout: 15000, }); }; + +const requestBodyUpdateExt11 = [ + { + "ROW": { + "key": "col1", + "label": "COLUMN_1" + }, + "COL": { + "key": "row3", + "label": "ROW_3" + } + }, + { + "ROW": { + "key": "col2", + "label": "COLUMN_2" + }, + "COL": {} + }, + { + "ROW": { + "key": "col3", + "label": "COLUMN_3" + }, + "COL": { + "key": "row2", + "label": "ROW_2" + } + }, +]; +const requestBodyUpdateExt12 = [ + { + "ROW": { + "key": "col1", + "label": "COLUMN_1" + }, + "COL": [ + { + "key": "row2", + "label": "ROW_2" + }, + { + "key": "row3", + "label": "ROW_3" + } + ] + }, + { + "ROW": { + "key": "col2", + "label": "COLUMN_2" + }, + "COL": [] + }, + { + "ROW": { + "key": "col3", + "label": "COLUMN_3" + }, + "COL": [ + { + "key": "row2", + "label": "ROW_2" + } + ] + }, +]; const updateMessage = ({ inquiryBnId, file }) => { /** @type {import('../../../../generated/services/InquiriesService').InquiriesService.postInquiriesServiceRcmsApi1Inquiry1MessagesUpdateInquiryBnIdRequest} */ const requestData = { inquiryBnId, requestBody: { - name: 'My Name', - from_mail: 'email@example.com', + name: 'Name2', + from_mail: 'email2@example.com', body: 'テストメッセージ2', - inquiry_category_id: 1, + inquiry_category_id: 3, ext_01: 'string2', ext_02: 'string2', ext_03: { @@ -132,6 +284,8 @@ const updateMessage = ({ inquiryBnId, file }) => { text: 'Text2', }, ext_10: '2020-04-24', + ext_11: requestBodyUpdateExt11, + ext_12: requestBodyUpdateExt12, validate_only: false, }, }; @@ -206,6 +360,8 @@ describe('Inquiry', () => { expect(sentMessage.ext_09.options, 'ext_09.options').to.equal('1'); expect(sentMessage.ext_09.text, 'ext_09.text').to.equal('Text1'); expect(sentMessage.ext_10, 'ext_10').to.equal('2020-04-23'); + expect(sentMessage.ext_11, 'ext_11').to.deep.equal(requestBodySendExt11); + expect(sentMessage.ext_12, 'ext_12').to.deep.equal(requestBodySendExt12); const updateFile = fixtures.rcms; const updateFileData = await upload({ path: updateFile }); @@ -213,9 +369,9 @@ describe('Inquiry', () => { const updatedMessage = await getMessageBy(addedId); expect(updatedMessage).to.exist; expect(updatedMessage.name, 'name').to.equal('My Name'); - expect(updatedMessage.from_mail, 'from_mail').to.equal('email@example.com'); + expect(updatedMessage.from_mail, 'from_mail').to.equal('email2@example.com'); expect(updatedMessage.body, 'body').to.equal('テストメッセージ2'); - expect(updatedMessage.inquiry_category_id, 'inquiry_category_id').to.equal(1); + expect(updatedMessage.inquiry_category_id, 'inquiry_category_id').to.equal(3); expect(updatedMessage.ext_01, 'ext_01').to.equal('string2'); expect(updatedMessage.ext_02, 'ext_02').to.equal('string2'); expect(updatedMessage.ext_03.key, 'ext_03.key').to.equal('2'); @@ -233,6 +389,8 @@ describe('Inquiry', () => { expect(updatedMessage.ext_09.options, 'ext_09.options').to.equal('2'); expect(updatedMessage.ext_09.text, 'ext_09.text').to.equal('Text2'); expect(updatedMessage.ext_10, 'ext_10').to.equal('2020-04-24'); + expect(updatedMessage.ext_11, 'ext_11').to.deep.equal(requestBodyUpdateExt11); + expect(updatedMessage.ext_12, 'ext_12').to.deep.equal(requestBodyUpdateExt12); }); });