Skip to content

Commit

Permalink
testInsert: don't generate default values for columns which appear in…
Browse files Browse the repository at this point in the history
… a constraint
  • Loading branch information
oyvindberg committed Jun 10, 2024
1 parent 342e0f9 commit 025dc8e
Show file tree
Hide file tree
Showing 15 changed files with 333 additions and 277 deletions.
8 changes: 7 additions & 1 deletion site-in/other-features/testing-with-random-values.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ c.setAutoCommit(false)
```

```scala mdoc
import adventureworks.customtypes.{Defaulted, TypoXml}
import adventureworks.customtypes.{Defaulted, TypoShort, TypoLocalDateTime, TypoXml}
import adventureworks.production.unitmeasure.UnitmeasureId
import adventureworks.TestInsert

Expand All @@ -41,6 +41,12 @@ val productCategory = testInsert.productionProductcategory()
val productSubcategory = testInsert.productionProductsubcategory(productCategory.productcategoryid)
val productModel = testInsert.productionProductmodel(catalogdescription = Some(new TypoXml("<xml/>")), instructions = Some(new TypoXml("<instructions/>")))
testInsert.productionProduct(
safetystocklevel = TypoShort(1),
reorderpoint = TypoShort(1),
standardcost = BigDecimal(1),
listprice = BigDecimal(1),
daystomanufacture = 10,
sellstartdate = TypoLocalDateTime.now,
sizeunitmeasurecode = Some(unitmeasure.unitmeasurecode),
weightunitmeasurecode = Some(unitmeasure.unitmeasurecode),
`class` = Some("H "),
Expand Down
2 changes: 1 addition & 1 deletion site-in/patterns/multi-repo.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ import scala.util.Random
val testInsert = new TestInsert(new Random(1))

val businessentityRow = testInsert.personBusinessentity()
val personRow = testInsert.personPerson(businessentityRow.businessentityid, FirstName("name"), persontype = "SC")
val personRow = testInsert.personPerson(businessentityRow.businessentityid, persontype = "SC", FirstName("name"))
val countryregionRow = testInsert.personCountryregion(CountryregionId("NOR"))
val salesterritoryRow = testInsert.salesSalesterritory(countryregionRow.countryregioncode)
val stateprovinceRow = testInsert.personStateprovince(countryregionRow.countryregioncode, salesterritoryRow.territoryid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import adventureworks.sales.salesorderheader.SalesorderheaderId
import adventureworks.sales.salesorderheader.SalesorderheaderRow
import adventureworks.sales.specialoffer.SpecialofferId
import adventureworks.sales.specialofferproduct.SpecialofferproductFields
import adventureworks.sales.specialofferproduct.SpecialofferproductId
import adventureworks.sales.specialofferproduct.SpecialofferproductRow
import typo.dsl.ForeignKey
import typo.dsl.Path
Expand Down Expand Up @@ -52,6 +53,11 @@ trait SalesorderdetailFields {
def compositeIdIn(compositeIds: Array[SalesorderdetailId]): SqlExpr[Boolean, Required] =
new CompositeIn(compositeIds)(TuplePart(salesorderid)(_.salesorderid), TuplePart(salesorderdetailid)(_.salesorderdetailid))

def extractSpecialofferproductIdIs(id: SpecialofferproductId): SqlExpr[Boolean, Required] =
specialofferid.isEqual(id.specialofferid).and(productid.isEqual(id.productid))
def extractSpecialofferproductIdIn(ids: Array[SpecialofferproductId]): SqlExpr[Boolean, Required] =
new CompositeIn(ids)(TuplePart(specialofferid)(_.specialofferid), TuplePart(productid)(_.productid))

}

object SalesorderdetailFields {
Expand Down

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions typo-tester-anorm/src/scala/adventureworks/RecordTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ class RecordTest extends AnyFunSuite with TypeCheckedTripleEquals {
withConnection { implicit c =>
val testInsert = new TestInsert(new Random(0))
val businessentityRow = testInsert.personBusinessentity()
val personRow = testInsert.personPerson(businessentityRow.businessentityid, FirstName("a"), persontype = "EM")
val personRow = testInsert.personPerson(businessentityRow.businessentityid, persontype = "EM", FirstName("a"))
testInsert.personEmailaddress(personRow.businessentityid, Some("[email protected]")): @nowarn
val employeeRow = testInsert.humanresourcesEmployee(personRow.businessentityid, gender = "M", maritalstatus = "M", hiredate = TypoLocalDate.apply("1997-01-01"))
val employeeRow =
testInsert.humanresourcesEmployee(personRow.businessentityid, gender = "M", maritalstatus = "M", birthdate = TypoLocalDate("1998-01-01"), hiredate = TypoLocalDate("1997-01-01"))
testInsert.salesSalesperson(employeeRow.businessentityid): @nowarn
personRowJoinSqlRepo() foreach println
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class PersonWithAddressesTest extends AnyFunSuite with TypeCheckedTripleEquals {
// insert randomly generated rows (with a fixed seed) we base the test on
val testInsert = new TestInsert(new Random(1))
val businessentityRow = testInsert.personBusinessentity()
val personRow = testInsert.personPerson(businessentityRow.businessentityid, FirstName("name"), persontype = "SC")
val personRow = testInsert.personPerson(businessentityRow.businessentityid, persontype = "SC", FirstName("name"))
val countryregionRow = testInsert.personCountryregion(CountryregionId("NOR"))
val salesterritoryRow = testInsert.salesSalesterritory(countryregionRow.countryregioncode)
val stateprovinceRow = testInsert.personStateprovince(countryregionRow.countryregioncode, salesterritoryRow.territoryid)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package adventureworks.production.product

import adventureworks.customtypes.{TypoLocalDateTime, TypoUUID, TypoXml}
import adventureworks.customtypes.{TypoLocalDateTime, TypoShort, TypoUUID, TypoXml}
import adventureworks.person.businessentity.{BusinessentityId, BusinessentityRepo, BusinessentityRepoImpl, BusinessentityRepoMock, BusinessentityRow}
import adventureworks.person.emailaddress.{EmailaddressRepo, EmailaddressRepoImpl, EmailaddressRepoMock, EmailaddressRow}
import adventureworks.person.person.{PersonRepo, PersonRepoImpl, PersonRepoMock, PersonRow}
Expand Down Expand Up @@ -31,6 +31,12 @@ class CompositeIdsTest extends AnyFunSuite with TypeCheckedTripleEquals {
val productSubcategory = testInsert.productionProductsubcategory(productCategory.productcategoryid)
val productModel = testInsert.productionProductmodel(catalogdescription = Some(new TypoXml("<xml/>")), instructions = Some(new TypoXml("<instructions/>")))
val product = testInsert.productionProduct(
safetystocklevel = TypoShort(1),
reorderpoint = TypoShort(1),
standardcost = BigDecimal(1),
listprice = BigDecimal(1),
daystomanufacture = 10,
sellstartdate = TypoLocalDateTime.now,
sizeunitmeasurecode = Some(unitmeasure.unitmeasurecode),
weightunitmeasurecode = Some(unitmeasure.unitmeasurecode),
`class` = Some("H "),
Expand All @@ -40,9 +46,9 @@ class CompositeIdsTest extends AnyFunSuite with TypeCheckedTripleEquals {
)

val now = TypoLocalDateTime.now
val ph1 = testInsert.productionProductcosthistory(product.productid, startdate = now, enddate = Some(now.map(_.plusDays(1))))
val ph2 = testInsert.productionProductcosthistory(product.productid, startdate = now.map(_.plusDays(1)), enddate = Some(now.map(_.plusDays(2))))
val ph3 = testInsert.productionProductcosthistory(product.productid, startdate = now.map(_.plusDays(2)), enddate = Some(now.map(_.plusDays(3))))
val ph1 = testInsert.productionProductcosthistory(product.productid, standardcost = BigDecimal(1), startdate = now, enddate = Some(now.map(_.plusDays(1))))
val ph2 = testInsert.productionProductcosthistory(product.productid, standardcost = BigDecimal(1), startdate = now.map(_.plusDays(1)), enddate = Some(now.map(_.plusDays(2))))
val ph3 = testInsert.productionProductcosthistory(product.productid, standardcost = BigDecimal(1), startdate = now.map(_.plusDays(2)), enddate = Some(now.map(_.plusDays(3))))
List(ph1.compositeId, ph2.compositeId, ph3.compositeId) foreach println
val wanted = Array(ph1.compositeId, ph2.compositeId, ph3.compositeId.copy(productid = ProductId(9999)))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ class ProductTest extends AnyFunSuite with TypeCheckedTripleEquals {
val productSubcategory = testInsert.productionProductsubcategory(productCategory.productcategoryid)
val productModel = testInsert.productionProductmodel(catalogdescription = Some(new TypoXml("<xml/>")), instructions = Some(new TypoXml("<instructions/>")))
val product = testInsert.productionProduct(
safetystocklevel = TypoShort(1),
reorderpoint = TypoShort(1),
standardcost = BigDecimal(1),
listprice = BigDecimal(1),
daystomanufacture = 10,
sellstartdate = TypoLocalDateTime.now,
sizeunitmeasurecode = Some(unitmeasure.unitmeasurecode),
weightunitmeasurecode = Some(unitmeasure.unitmeasurecode),
`class` = Some("H "),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import adventureworks.sales.salesorderheader.SalesorderheaderId
import adventureworks.sales.salesorderheader.SalesorderheaderRow
import adventureworks.sales.specialoffer.SpecialofferId
import adventureworks.sales.specialofferproduct.SpecialofferproductFields
import adventureworks.sales.specialofferproduct.SpecialofferproductId
import adventureworks.sales.specialofferproduct.SpecialofferproductRow
import typo.dsl.ForeignKey
import typo.dsl.Path
Expand Down Expand Up @@ -52,6 +53,11 @@ trait SalesorderdetailFields {
def compositeIdIn(compositeIds: Array[SalesorderdetailId]): SqlExpr[Boolean, Required] =
new CompositeIn(compositeIds)(TuplePart(salesorderid)(_.salesorderid), TuplePart(salesorderdetailid)(_.salesorderdetailid))

def extractSpecialofferproductIdIs(id: SpecialofferproductId): SqlExpr[Boolean, Required] =
specialofferid.isEqual(id.specialofferid).and(productid.isEqual(id.productid))
def extractSpecialofferproductIdIn(ids: Array[SpecialofferproductId]): SqlExpr[Boolean, Required] =
new CompositeIn(ids)(TuplePart(specialofferid)(_.specialofferid), TuplePart(productid)(_.productid))

}

object SalesorderdetailFields {
Expand Down
Loading

0 comments on commit 025dc8e

Please sign in to comment.