mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-19 05:30:43 +00:00
Add toQRecordOnlyChangedFields
This commit is contained in:
@ -67,6 +67,35 @@ class QRecordEntityTest extends BaseTest
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testItemToQRecordOnlyChangedFields() throws QException
|
||||
{
|
||||
Item item = new Item(new QRecord()
|
||||
.withValue("sku", "ABC-123")
|
||||
.withValue("description", null)
|
||||
.withValue("quantity", 47)
|
||||
.withValue("price", new BigDecimal("3.50"))
|
||||
.withValue("isFeatured", true));
|
||||
|
||||
QRecord qRecordOnlyChangedFields = item.toQRecordOnlyChangedFields();
|
||||
assertTrue(qRecordOnlyChangedFields.getValues().isEmpty());
|
||||
|
||||
item.setDescription("My Changed Item");
|
||||
qRecordOnlyChangedFields = item.toQRecordOnlyChangedFields();
|
||||
assertEquals(1, qRecordOnlyChangedFields.getValues().size());
|
||||
assertEquals("My Changed Item", qRecordOnlyChangedFields.getValueString("description"));
|
||||
|
||||
item.setPrice(null);
|
||||
qRecordOnlyChangedFields = item.toQRecordOnlyChangedFields();
|
||||
assertEquals(2, qRecordOnlyChangedFields.getValues().size());
|
||||
assertNull(qRecordOnlyChangedFields.getValueString("price"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
|
@ -24,6 +24,7 @@ package com.kingsrook.qqq.backend.core.model.data.testentities;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import com.kingsrook.qqq.backend.core.model.data.QField;
|
||||
import com.kingsrook.qqq.backend.core.model.data.QRecord;
|
||||
import com.kingsrook.qqq.backend.core.model.data.QRecordEntity;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.DisplayFormat;
|
||||
|
||||
@ -49,6 +50,27 @@ public class Item extends QRecordEntity
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Constructor
|
||||
**
|
||||
*******************************************************************************/
|
||||
public Item()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Constructor
|
||||
**
|
||||
*******************************************************************************/
|
||||
public Item(QRecord qRecord)
|
||||
{
|
||||
populateFromQRecord(qRecord);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for sku
|
||||
**
|
||||
|
Reference in New Issue
Block a user