All files / lib/state-machines OrderStatusValidator.ts

68.42% Statements 13/19
60% Branches 9/15
100% Functions 1/1
68.42% Lines 13/19
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37  1x 1x     8x   2x 1x   1x             1x     1x     2x 1x   1x                 2x  
import { ORDER_STATUS_ENUM } from '../models/Enums';
export class OrderStatusValidator {
    static validateState(currentState:ORDER_STATUS_ENUM, nextState: ORDER_STATUS_ENUM): boolean {
        switch (nextState) {
            case ORDER_STATUS_ENUM.PENDING:
                if (currentState !== ORDER_STATUS_ENUM.NEW) {
                    return false;
                }
                return true;
            case ORDER_STATUS_ENUM.PROCESSING:
                if (currentState !== ORDER_STATUS_ENUM.PENDING) {
                    return false;
                }
                return true;
            case ORDER_STATUS_ENUM.CANCELED: { //Quote can be CANCELED at any state
                return true;
            }
            case ORDER_STATUS_ENUM.CLOSED: { //Quote can be CLOSED at any state
                return true;
            }
            case ORDER_STATUS_ENUM.DELIVERED: {
                if (currentState !== ORDER_STATUS_ENUM.OUT_FOR_DELIVERY) {
                    return false;
                }
                return true;
            }
            case ORDER_STATUS_ENUM.DELIVERED: {
                if (currentState !== ORDER_STATUS_ENUM.OUT_FOR_DELIVERY) {
                    return false;
                }
                return true;
            }
            default:
                return false;
        }
    }
}