mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 21:20:45 +00:00
CE-882 Initial build of processes to manage shared records
This commit is contained in:
@ -0,0 +1,132 @@
|
||||
/*
|
||||
* QQQ - Low-code Application Framework for Engineers.
|
||||
* Copyright (C) 2021-2024. Kingsrook, LLC
|
||||
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
|
||||
* contact@kingsrook.com
|
||||
* https://github.com/Kingsrook/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qqq.backend.core.processes.implementations.sharing;
|
||||
|
||||
|
||||
import com.kingsrook.qqq.backend.core.BaseTest;
|
||||
import com.kingsrook.qqq.backend.core.actions.tables.GetAction;
|
||||
import com.kingsrook.qqq.backend.core.actions.tables.InsertAction;
|
||||
import com.kingsrook.qqq.backend.core.context.QContext;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepInput;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepOutput;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.get.GetInput;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.insert.InsertInput;
|
||||
import com.kingsrook.qqq.backend.core.model.data.QRecord;
|
||||
import com.kingsrook.qqq.backend.core.model.savedreports.ReportColumns;
|
||||
import com.kingsrook.qqq.backend.core.model.savedreports.SavedReport;
|
||||
import com.kingsrook.qqq.backend.core.model.savedreports.SavedReportsMetaDataProvider;
|
||||
import com.kingsrook.qqq.backend.core.model.savedreports.SharedSavedReport;
|
||||
import com.kingsrook.qqq.backend.core.utils.JsonUtils;
|
||||
import com.kingsrook.qqq.backend.core.utils.TestUtils;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Unit test for DeleteSharedRecordProcess
|
||||
*******************************************************************************/
|
||||
class DeleteSharedRecordProcessTest extends BaseTest
|
||||
{
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@BeforeEach
|
||||
void beforeEach() throws Exception
|
||||
{
|
||||
new SavedReportsMetaDataProvider().defineAll(QContext.getQInstance(), TestUtils.MEMORY_BACKEND_NAME, TestUtils.MEMORY_BACKEND_NAME, null);
|
||||
|
||||
new InsertAction().execute(new InsertInput(SavedReport.TABLE_NAME).withRecordEntity(new SavedReport()
|
||||
.withTableName(TestUtils.TABLE_NAME_PERSON_MEMORY)
|
||||
.withLabel("Test")
|
||||
.withColumnsJson(JsonUtils.toJson(new ReportColumns().withColumn("id")))
|
||||
));
|
||||
|
||||
new InsertAction().execute(new InsertInput(SharedSavedReport.TABLE_NAME).withRecordEntity(new SharedSavedReport()
|
||||
.withSavedReportId(1)
|
||||
.withUserId(BaseTest.DEFAULT_USER_ID)
|
||||
.withScope(ShareScope.READ_WRITE.getPossibleValueId())
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testFailCases() throws QException
|
||||
{
|
||||
RunBackendStepInput input = new RunBackendStepInput();
|
||||
RunBackendStepOutput output = new RunBackendStepOutput();
|
||||
DeleteSharedRecordProcess processStep = new DeleteSharedRecordProcess();
|
||||
|
||||
assertThatThrownBy(() -> processStep.run(input, output)).hasMessageContaining("Missing required input: tableName");
|
||||
input.addValue("tableName", SavedReport.TABLE_NAME);
|
||||
assertThatThrownBy(() -> processStep.run(input, output)).hasMessageContaining("Missing required input: recordId");
|
||||
input.addValue("recordId", 1);
|
||||
assertThatThrownBy(() -> processStep.run(input, output)).hasMessageContaining("Missing required input: shareId");
|
||||
input.addValue("shareId", 3);
|
||||
|
||||
///////////////////////////////////////////////////
|
||||
// fail because the requested record isn't found //
|
||||
///////////////////////////////////////////////////
|
||||
assertThatThrownBy(() -> processStep.run(input, output)).hasMessageContaining("Error deleting shared record: No record was found to delete");
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// now fail because a different user (than the owner, who did the initial delete) is trying to share //
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
QContext.setQSession(newSession("not-" + DEFAULT_USER_ID));
|
||||
input.addValue("shareId", 1);
|
||||
assertThatThrownBy(() -> processStep.run(input, output)).hasMessageContaining("not the owner of this record");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testSuccess() throws QException
|
||||
{
|
||||
RunBackendStepInput input = new RunBackendStepInput();
|
||||
RunBackendStepOutput output = new RunBackendStepOutput();
|
||||
DeleteSharedRecordProcess processStep = new DeleteSharedRecordProcess();
|
||||
|
||||
input.addValue("tableName", SavedReport.TABLE_NAME);
|
||||
input.addValue("recordId", 1);
|
||||
input.addValue("shareId", 1);
|
||||
|
||||
//////////////////////////////////////////
|
||||
// assert the shared record got deleted //
|
||||
//////////////////////////////////////////
|
||||
processStep.run(input, output);
|
||||
|
||||
QRecord sharedSavedReportRecord = new GetAction().executeForRecord(new GetInput(SharedSavedReport.TABLE_NAME).withPrimaryKey(1));
|
||||
assertNull(sharedSavedReportRecord);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,144 @@
|
||||
/*
|
||||
* QQQ - Low-code Application Framework for Engineers.
|
||||
* Copyright (C) 2021-2024. Kingsrook, LLC
|
||||
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
|
||||
* contact@kingsrook.com
|
||||
* https://github.com/Kingsrook/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qqq.backend.core.processes.implementations.sharing;
|
||||
|
||||
|
||||
import com.kingsrook.qqq.backend.core.BaseTest;
|
||||
import com.kingsrook.qqq.backend.core.actions.tables.GetAction;
|
||||
import com.kingsrook.qqq.backend.core.actions.tables.InsertAction;
|
||||
import com.kingsrook.qqq.backend.core.context.QContext;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepInput;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepOutput;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.get.GetInput;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.insert.InsertInput;
|
||||
import com.kingsrook.qqq.backend.core.model.data.QRecord;
|
||||
import com.kingsrook.qqq.backend.core.model.savedreports.ReportColumns;
|
||||
import com.kingsrook.qqq.backend.core.model.savedreports.SavedReport;
|
||||
import com.kingsrook.qqq.backend.core.model.savedreports.SavedReportsMetaDataProvider;
|
||||
import com.kingsrook.qqq.backend.core.model.savedreports.SharedSavedReport;
|
||||
import com.kingsrook.qqq.backend.core.utils.JsonUtils;
|
||||
import com.kingsrook.qqq.backend.core.utils.TestUtils;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Unit test for EditSharedRecordProcess
|
||||
*******************************************************************************/
|
||||
class EditSharedRecordProcessTest extends BaseTest
|
||||
{
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@BeforeEach
|
||||
void beforeEach() throws Exception
|
||||
{
|
||||
new SavedReportsMetaDataProvider().defineAll(QContext.getQInstance(), TestUtils.MEMORY_BACKEND_NAME, TestUtils.MEMORY_BACKEND_NAME, null);
|
||||
|
||||
new InsertAction().execute(new InsertInput(SavedReport.TABLE_NAME).withRecordEntity(new SavedReport()
|
||||
.withTableName(TestUtils.TABLE_NAME_PERSON_MEMORY)
|
||||
.withLabel("Test")
|
||||
.withColumnsJson(JsonUtils.toJson(new ReportColumns().withColumn("id")))
|
||||
));
|
||||
|
||||
new InsertAction().execute(new InsertInput(SharedSavedReport.TABLE_NAME).withRecordEntity(new SharedSavedReport()
|
||||
.withSavedReportId(1)
|
||||
.withUserId(BaseTest.DEFAULT_USER_ID)
|
||||
.withScope(ShareScope.READ_WRITE.getPossibleValueId())
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testFailCases() throws QException
|
||||
{
|
||||
RunBackendStepInput input = new RunBackendStepInput();
|
||||
RunBackendStepOutput output = new RunBackendStepOutput();
|
||||
EditSharedRecordProcess processStep = new EditSharedRecordProcess();
|
||||
|
||||
assertThatThrownBy(() -> processStep.run(input, output)).hasMessageContaining("Missing required input: tableName");
|
||||
input.addValue("tableName", SavedReport.TABLE_NAME);
|
||||
assertThatThrownBy(() -> processStep.run(input, output)).hasMessageContaining("Missing required input: recordId");
|
||||
input.addValue("recordId", 1);
|
||||
assertThatThrownBy(() -> processStep.run(input, output)).hasMessageContaining("Missing required input: scopeId");
|
||||
input.addValue("scopeId", ShareScope.READ_WRITE.getPossibleValueId());
|
||||
assertThatThrownBy(() -> processStep.run(input, output)).hasMessageContaining("Missing required input: shareId");
|
||||
input.addValue("shareId", 3);
|
||||
|
||||
///////////////////////////////////////////////////
|
||||
// fail because the requested record isn't found //
|
||||
///////////////////////////////////////////////////
|
||||
assertThatThrownBy(() -> processStep.run(input, output)).hasMessageContaining("Error editing shared record: No record was found to update");
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// now fail because a different user (than the owner, who did the initial edit) is trying to share //
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
QContext.setQSession(newSession("not-" + DEFAULT_USER_ID));
|
||||
input.addValue("shareId", 1);
|
||||
assertThatThrownBy(() -> processStep.run(input, output)).hasMessageContaining("not the owner of this record");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testSuccess() throws QException
|
||||
{
|
||||
RunBackendStepInput input = new RunBackendStepInput();
|
||||
RunBackendStepOutput output = new RunBackendStepOutput();
|
||||
EditSharedRecordProcess processStep = new EditSharedRecordProcess();
|
||||
|
||||
///////////////////////////
|
||||
// assert original value //
|
||||
///////////////////////////
|
||||
QRecord sharedSavedReportRecord = new GetAction().executeForRecord(new GetInput(SharedSavedReport.TABLE_NAME).withPrimaryKey(1));
|
||||
assertEquals(ShareScope.READ_WRITE.getPossibleValueId(), sharedSavedReportRecord.getValueString("scope"));
|
||||
|
||||
input.addValue("tableName", SavedReport.TABLE_NAME);
|
||||
input.addValue("recordId", 1);
|
||||
input.addValue("shareId", 1);
|
||||
input.addValue("scopeId", ShareScope.READ_ONLY.getPossibleValueId());
|
||||
|
||||
/////////////////////////////////////////
|
||||
// assert the shared record got edited //
|
||||
/////////////////////////////////////////
|
||||
processStep.run(input, output);
|
||||
|
||||
//////////////////////////
|
||||
// assert updated value //
|
||||
//////////////////////////
|
||||
sharedSavedReportRecord = new GetAction().executeForRecord(new GetInput(SharedSavedReport.TABLE_NAME).withPrimaryKey(1));
|
||||
assertEquals(ShareScope.READ_ONLY.getPossibleValueId(), sharedSavedReportRecord.getValueString("scope"));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* QQQ - Low-code Application Framework for Engineers.
|
||||
* Copyright (C) 2021-2024. Kingsrook, LLC
|
||||
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
|
||||
* contact@kingsrook.com
|
||||
* https://github.com/Kingsrook/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qqq.backend.core.processes.implementations.sharing;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import com.kingsrook.qqq.backend.core.BaseTest;
|
||||
import com.kingsrook.qqq.backend.core.actions.tables.InsertAction;
|
||||
import com.kingsrook.qqq.backend.core.context.QContext;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepInput;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepOutput;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.insert.InsertInput;
|
||||
import com.kingsrook.qqq.backend.core.model.data.QRecord;
|
||||
import com.kingsrook.qqq.backend.core.model.savedreports.ReportColumns;
|
||||
import com.kingsrook.qqq.backend.core.model.savedreports.SavedReport;
|
||||
import com.kingsrook.qqq.backend.core.model.savedreports.SavedReportsMetaDataProvider;
|
||||
import com.kingsrook.qqq.backend.core.model.savedreports.SharedSavedReport;
|
||||
import com.kingsrook.qqq.backend.core.utils.JsonUtils;
|
||||
import com.kingsrook.qqq.backend.core.utils.TestUtils;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Unit test for GetSharedRecordsProcess
|
||||
*******************************************************************************/
|
||||
class GetSharedRecordsProcessTest extends BaseTest
|
||||
{
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@BeforeEach
|
||||
void beforeEach() throws Exception
|
||||
{
|
||||
new SavedReportsMetaDataProvider().defineAll(QContext.getQInstance(), TestUtils.MEMORY_BACKEND_NAME, TestUtils.MEMORY_BACKEND_NAME, null);
|
||||
|
||||
new InsertAction().execute(new InsertInput(SavedReport.TABLE_NAME).withRecordEntity(new SavedReport()
|
||||
.withTableName(TestUtils.TABLE_NAME_PERSON_MEMORY)
|
||||
.withLabel("Test")
|
||||
.withColumnsJson(JsonUtils.toJson(new ReportColumns().withColumn("id")))));
|
||||
|
||||
new InsertAction().execute(new InsertInput(SharedSavedReport.TABLE_NAME).withRecordEntity(new SharedSavedReport()
|
||||
.withScope(ShareScope.READ_WRITE.getPossibleValueId())
|
||||
.withUserId("007")
|
||||
.withSavedReportId(1)
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void test() throws QException
|
||||
{
|
||||
RunBackendStepInput input = new RunBackendStepInput();
|
||||
RunBackendStepOutput output = new RunBackendStepOutput();
|
||||
GetSharedRecordsProcess processStep = new GetSharedRecordsProcess();
|
||||
|
||||
input.addValue("tableName", SavedReport.TABLE_NAME);
|
||||
input.addValue("recordId", 1);
|
||||
processStep.run(input, output);
|
||||
|
||||
List<QRecord> resultList = (List<QRecord>) output.getValue("resultList");
|
||||
assertEquals(1, resultList.size());
|
||||
|
||||
QRecord outputRecord = resultList.get(0);
|
||||
assertEquals(1, outputRecord.getValueInteger("id"));
|
||||
assertEquals(ShareScope.READ_WRITE.getPossibleValueId(), outputRecord.getValueString("scopeId"));
|
||||
assertEquals("user", outputRecord.getValueString("audienceType"));
|
||||
assertEquals("007", outputRecord.getValueString("audienceId"));
|
||||
assertEquals("user 007", outputRecord.getValueString("audienceLabel"));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,146 @@
|
||||
/*
|
||||
* QQQ - Low-code Application Framework for Engineers.
|
||||
* Copyright (C) 2021-2024. Kingsrook, LLC
|
||||
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
|
||||
* contact@kingsrook.com
|
||||
* https://github.com/Kingsrook/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qqq.backend.core.processes.implementations.sharing;
|
||||
|
||||
|
||||
import com.kingsrook.qqq.backend.core.BaseTest;
|
||||
import com.kingsrook.qqq.backend.core.actions.tables.GetAction;
|
||||
import com.kingsrook.qqq.backend.core.actions.tables.InsertAction;
|
||||
import com.kingsrook.qqq.backend.core.context.QContext;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepInput;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepOutput;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.get.GetInput;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.insert.InsertInput;
|
||||
import com.kingsrook.qqq.backend.core.model.data.QRecord;
|
||||
import com.kingsrook.qqq.backend.core.model.savedreports.ReportColumns;
|
||||
import com.kingsrook.qqq.backend.core.model.savedreports.SavedReport;
|
||||
import com.kingsrook.qqq.backend.core.model.savedreports.SavedReportsMetaDataProvider;
|
||||
import com.kingsrook.qqq.backend.core.model.savedreports.SharedSavedReport;
|
||||
import com.kingsrook.qqq.backend.core.utils.JsonUtils;
|
||||
import com.kingsrook.qqq.backend.core.utils.TestUtils;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Unit test for InsertSharedRecordProcess
|
||||
*******************************************************************************/
|
||||
class InsertSharedRecordProcessTest extends BaseTest
|
||||
{
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@BeforeEach
|
||||
void beforeEach() throws Exception
|
||||
{
|
||||
new SavedReportsMetaDataProvider().defineAll(QContext.getQInstance(), TestUtils.MEMORY_BACKEND_NAME, TestUtils.MEMORY_BACKEND_NAME, null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testFailCases() throws QException
|
||||
{
|
||||
RunBackendStepInput input = new RunBackendStepInput();
|
||||
RunBackendStepOutput output = new RunBackendStepOutput();
|
||||
InsertSharedRecordProcess processStep = new InsertSharedRecordProcess();
|
||||
|
||||
assertThatThrownBy(() -> processStep.run(input, output)).hasMessageContaining("Missing required input: tableName");
|
||||
input.addValue("tableName", SavedReport.TABLE_NAME);
|
||||
assertThatThrownBy(() -> processStep.run(input, output)).hasMessageContaining("Missing required input: recordId");
|
||||
input.addValue("recordId", 1);
|
||||
assertThatThrownBy(() -> processStep.run(input, output)).hasMessageContaining("Missing required input: audienceType");
|
||||
input.addValue("audienceType", "user");
|
||||
assertThatThrownBy(() -> processStep.run(input, output)).hasMessageContaining("Missing required input: audienceId");
|
||||
input.addValue("audienceId", "darin@kingsrook.com");
|
||||
assertThatThrownBy(() -> processStep.run(input, output)).hasMessageContaining("Missing required input: scopeId");
|
||||
input.addValue("scopeId", ShareScope.READ_WRITE);
|
||||
|
||||
//////////////////////////////
|
||||
// try a non-sharable table //
|
||||
//////////////////////////////
|
||||
input.addValue("tableName", TestUtils.TABLE_NAME_PERSON_MEMORY);
|
||||
assertThatThrownBy(() -> processStep.run(input, output)).hasMessageContaining("is not shareable");
|
||||
input.addValue("tableName", SavedReport.TABLE_NAME);
|
||||
|
||||
///////////////////////////////////////////////////
|
||||
// fail because the requested record isn't found //
|
||||
///////////////////////////////////////////////////
|
||||
assertThatThrownBy(() -> processStep.run(input, output)).hasMessageContaining("record could not be found in table, savedReport, with primary key: 1");
|
||||
new InsertAction().execute(new InsertInput(SavedReport.TABLE_NAME).withRecordEntity(new SavedReport()
|
||||
.withTableName(TestUtils.TABLE_NAME_PERSON_MEMORY)
|
||||
.withLabel("Test")
|
||||
.withColumnsJson(JsonUtils.toJson(new ReportColumns().withColumn("id")))
|
||||
));
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// now fail because a different user (than the owner, who did the initial insert) is trying to share //
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
QContext.setQSession(newSession("not-" + DEFAULT_USER_ID));
|
||||
assertThatThrownBy(() -> processStep.run(input, output)).hasMessageContaining("not the owner of this record");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testSuccess() throws QException
|
||||
{
|
||||
RunBackendStepInput input = new RunBackendStepInput();
|
||||
RunBackendStepOutput output = new RunBackendStepOutput();
|
||||
InsertSharedRecordProcess processStep = new InsertSharedRecordProcess();
|
||||
|
||||
input.addValue("tableName", SavedReport.TABLE_NAME);
|
||||
input.addValue("recordId", 1);
|
||||
input.addValue("audienceType", "user");
|
||||
input.addValue("audienceId", "darin@kingsrook.com");
|
||||
input.addValue("scopeId", ShareScope.READ_WRITE);
|
||||
|
||||
new InsertAction().execute(new InsertInput(SavedReport.TABLE_NAME).withRecordEntity(new SavedReport()
|
||||
.withTableName(TestUtils.TABLE_NAME_PERSON_MEMORY)
|
||||
.withLabel("Test")
|
||||
.withColumnsJson(JsonUtils.toJson(new ReportColumns().withColumn("id")))
|
||||
));
|
||||
|
||||
////////////////////////////////////////
|
||||
// assert the shared record got built //
|
||||
////////////////////////////////////////
|
||||
processStep.run(input, output);
|
||||
|
||||
QRecord sharedSavedReportRecord = new GetAction().executeForRecord(new GetInput(SharedSavedReport.TABLE_NAME).withPrimaryKey(1));
|
||||
assertNotNull(sharedSavedReportRecord);
|
||||
assertEquals(1, sharedSavedReportRecord.getValueInteger("savedReportId"));
|
||||
assertEquals("darin@kingsrook.com", sharedSavedReportRecord.getValueString("userId"));
|
||||
assertEquals(ShareScope.READ_WRITE.getPossibleValueId(), sharedSavedReportRecord.getValueString("scope"));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* QQQ - Low-code Application Framework for Engineers.
|
||||
* Copyright (C) 2021-2024. Kingsrook, LLC
|
||||
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
|
||||
* contact@kingsrook.com
|
||||
* https://github.com/Kingsrook/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qqq.backend.core.processes.implementations.sharing;
|
||||
|
||||
|
||||
import com.kingsrook.qqq.backend.core.BaseTest;
|
||||
import com.kingsrook.qqq.backend.core.context.QContext;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Unit test for SharingMetaDataProvider
|
||||
*******************************************************************************/
|
||||
class SharingMetaDataProviderTest extends BaseTest
|
||||
{
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void test() throws QException
|
||||
{
|
||||
new SharingMetaDataProvider().defineAll(QContext.getQInstance(), null);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user