Skip to content

Commit

Permalink
feat: cover the case where validFrom is null
Browse files Browse the repository at this point in the history
  • Loading branch information
monitz87 committed Oct 5, 2020
1 parent 0a12b2a commit 7dd72cf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/api/entities/Instruction/__tests__/index.ts
Expand Up @@ -108,18 +108,20 @@ describe('Instruction class', () => {

instructionDetailsStub.resolves({
...queryResult,
// eslint-disable-next-line @typescript-eslint/camelcase
/* eslint-disable @typescript-eslint/camelcase */
valid_from: dsMockUtils.createMockOption(),
settlement_type: dsMockUtils.createMockSettlementType({
SettleOnBlock: dsMockUtils.createMockU32(endBlock.toNumber()),
}),
/* eslint-enable @typescript-eslint/camelcase */
});

result = await instruction.details();

expect(result).toEqual({
status,
createdAt,
validFrom,
validFrom: null,
type,
endBlock,
});
Expand Down
4 changes: 2 additions & 2 deletions src/api/entities/Instruction/index.ts
Expand Up @@ -71,8 +71,8 @@ export class Instruction extends Entity<UniqueIdentifiers> {

const details = {
status: meshInstructionStatusToInstructionStatus(status),
createdAt: momentToDate(createdAt.unwrap()), // NOTE @monitz87: I'm pretty sure neither of these two can be null, but I'll ask
validFrom: momentToDate(validFrom.unwrap()),
createdAt: momentToDate(createdAt.unwrap()), // NOTE @monitz87: I'm pretty sure this can't be null, but I'll ask
validFrom: validFrom.isSome ? momentToDate(validFrom.unwrap()) : null,
};

if (type.isSettleOnAuthorization) {
Expand Down
5 changes: 4 additions & 1 deletion src/api/entities/Instruction/types.ts
Expand Up @@ -15,7 +15,10 @@ export enum InstructionType {
export type InstructionDetails = {
status: InstructionStatus;
createdAt: Date;
validFrom: Date;
/**
* If null, the instruction is valid immediately
*/
validFrom: Date | null;
} & (
| {
type: InstructionType.SettleOnAuthorization;
Expand Down

0 comments on commit 7dd72cf

Please sign in to comment.