Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/groovy/org/pih/warehouse/api/StockMovement.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,8 @@ class StockMovement implements Validateable{
}

// Because this function needs to handle more than one enum, I left the argument's type as def
static String getTranslatedDisplayStatus(def status) {
return applicationTagLib.message(code: 'enum.' + status?.getClass()?.getSimpleName() + '.' + status)
String getTranslatedDisplayStatus(def status) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't get a chance to review this but could you please change the implementation of this method to be ...

   return applicationTagLib.message(code: 'enum.' + status?.class?.simpleName + '.' + status)

Also why do we need a second method to get the translated display status when the original getDisplayStatus() method already does the localization?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also why do we need a second method to get the translated display status when the original getDisplayStatus() method already does the localization?

I am not sure if I understand what you mean, but I moved this to a separate function because I wanted to make the code more clean 🤔

return applicationTagLib.message(code: 'enum.' + status?.class?.simpleName + '.' + status)
}

// Mapping statuses for display for the requestor's dashboard
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package unit.org.pih.warehouse.core

import org.pih.warehouse.inventory.StockMovementStatusCode
import org.pih.warehouse.requisition.Requisition
import org.pih.warehouse.shipping.Shipment
import org.pih.warehouse.shipping.ShipmentStatusCode
import spock.lang.Specification
import spock.lang.Unroll
import org.pih.warehouse.requisition.RequisitionStatus
import org.pih.warehouse.api.StockMovement

@Unroll
class StockMovementSpec extends Specification {

void 'StockMovement.getDisplayStatus() should return: #expected for requisition status #status'() {
when:
StockMovement stockMovement = new StockMovement() {
@Override
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work on these tests!

In general I'm not the hugest fan of overriding methods in a test like this. Usually I'd try to Stub out the tagLib but it doesn't look like that'd be easy to do since it's fetched statically in the StockMovement. You could maybe Stub the StockMovemnt instance itself with something like:

StockMovement stockMovement = Stub(StockMovement) {
            getTranslatedDisplayStatus(def status) >> status.name()
        }

but that's essentially what you're doing anyways with your override (and I don't even know if the above code would work). I'm okay with your approach here.

Yay tests!

String getTranslatedDisplayStatus(def status) {
return status.name()
}
}
stockMovement.requisition = new Requisition()
stockMovement.requisition.status = status

then:
stockMovement.getDisplayStatus() == expected.name()

where:
status || expected
RequisitionStatus.APPROVED || StockMovementStatusCode.APPROVED
RequisitionStatus.REJECTED || StockMovementStatusCode.REJECTED
RequisitionStatus.PENDING_APPROVAL || StockMovementStatusCode.PENDING_APPROVAL
RequisitionStatus.VERIFYING || StockMovementStatusCode.IN_PROGRESS
RequisitionStatus.PICKING || StockMovementStatusCode.IN_PROGRESS
RequisitionStatus.PICKED || StockMovementStatusCode.IN_PROGRESS
RequisitionStatus.CHECKING || StockMovementStatusCode.IN_PROGRESS
}

void 'StockMovement.getDisplayStatus() should return: #expected for shipment status #status'() {
when:
StockMovement stockMovement = new StockMovement() {
@Override
String getTranslatedDisplayStatus(def status) {
return status.name()
}
}
stockMovement.shipment = new Shipment()
stockMovement.shipment.status.code = status

then:
stockMovement.getDisplayStatus() == expected.name()

where:
status || expected
ShipmentStatusCode.CREATED || ShipmentStatusCode.PENDING
ShipmentStatusCode.PARTIALLY_RECEIVED || ShipmentStatusCode.PENDING
ShipmentStatusCode.RECEIVED || ShipmentStatusCode.PENDING
ShipmentStatusCode.SHIPPED || ShipmentStatusCode.PENDING
}
}