|
| 1 | +packageunit.org.pih.warehouse.inventory |
| 2 | + |
| 3 | +importgrails.testing.gorm.DomainUnitTest |
| 4 | +importspock.lang.Specification |
| 5 | +importspock.lang.Unroll |
| 6 | + |
| 7 | +importorg.pih.warehouse.inventory.TransactionCode |
| 8 | +importorg.pih.warehouse.inventory.TransactionType |
| 9 | + |
| 10 | +@Unroll |
| 11 | +classTransactionTypeSpecextendsSpecificationimplementsDomainUnitTest<TransactionType> { |
| 12 | + |
| 13 | +def'should return #expected with error code #expectedErrorCode when validating transaction type given name #value'() { |
| 14 | +given:"the name is #value" |
| 15 | + domain.name= value |
| 16 | + |
| 17 | +when:"the transaction type is validated" |
| 18 | +boolean actual= domain.validate(["name"]) |
| 19 | + |
| 20 | +then:"the name property should be valid or invalid with the expected error code" |
| 21 | + actual== expected |
| 22 | + domain.errors.getFieldError("name")?.code== expectedErrorCode |
| 23 | + |
| 24 | +where: |
| 25 | + value|| expected | expectedErrorCode |
| 26 | +null||false |'nullable' |
| 27 | +'a'*256||false |'maxSize.exceeded' |
| 28 | +'b'*255||true |null |
| 29 | +'Dummy Name'||true |null |
| 30 | + } |
| 31 | + |
| 32 | +void'should return #expected with error code #expectedErrorCode when validating transaction type given name #value'() { |
| 33 | +when: |
| 34 | + domain.description= value |
| 35 | + |
| 36 | +then: |
| 37 | +assert domain.validate(['description'])== expected |
| 38 | +assert domain.errors.getFieldError("description")?.code== expectedErrorCode |
| 39 | + |
| 40 | +where: |
| 41 | + value|| expected | expectedErrorCode |
| 42 | +null||true |null |
| 43 | +'a'*256||false |'maxSize.exceeded' |
| 44 | +'Dummy description'||true |null |
| 45 | + } |
| 46 | + |
| 47 | +void'compareName should expect the names to be the same'() { |
| 48 | +given:"a valid transaction type with multiple" |
| 49 | +TransactionType transactionType= |
| 50 | +newTransactionType(name:"Debit|sp:Débito|fr:Débit",transactionCode:TransactionCode.DEBIT) |
| 51 | + |
| 52 | +when:"the name is compared with debit" |
| 53 | +boolean nameIsSame= transactionType.compareName("Debit") |
| 54 | + |
| 55 | +then:"the name is the same" |
| 56 | +assert nameIsSame |
| 57 | + } |
| 58 | + |
| 59 | +void'should return #expected with error code #expectedErrorCode when validating transaction type given name #value'() { |
| 60 | +given: |
| 61 | + domain.transactionCode= value |
| 62 | + |
| 63 | +when: |
| 64 | +boolean actual= domain.validate(['transactionCode']) |
| 65 | + |
| 66 | +then: |
| 67 | + actual== expected |
| 68 | + domain.errors.getFieldError("transactionCode")?.code== expectedErrorCode |
| 69 | + |
| 70 | +where: |
| 71 | + value|| expected | expectedErrorCode |
| 72 | +null||false |'nullable' |
| 73 | +TransactionCode.DEBIT||true |null |
| 74 | + } |
| 75 | + |
| 76 | +void'isAdjustment should return #expected when given name #value'() { |
| 77 | +given: |
| 78 | + domain.name= value |
| 79 | + |
| 80 | +expect: |
| 81 | + domain.isAdjustment()== expected |
| 82 | + |
| 83 | +where: |
| 84 | + value|| expected |
| 85 | +'Adjustment|fr:Ajustement|es:Ajustamiento'||true |
| 86 | +'NO_Adjustment'||false |
| 87 | +'Adjustment'||true |
| 88 | + } |
| 89 | +} |