Skip to content

Commit

Permalink
Tests: Add acceptance tests for syntax error and missing files
Browse files Browse the repository at this point in the history
 - Add two acceptance tests:

   - not throwing exception when an unexpected error occurs, i.e., a
     file that does not exist.

   - not throwing exception when syntax errors are detected in project
     descrioptions;

 - Fix ESLint & TSLint error, including those related to explicit
   'any' type
  • Loading branch information
Franck Chauvel committed Jan 28, 2020
1 parent 64c0594 commit d6ffa92
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 16 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ RPP checks for the following:
- Activities without leader
- Idle partners (without any role)


[workplan-schema]: https://github.com/fchauvel/rpp/blob/058f1722d116955bb9a018dcca6287a926044670/src/storage/adapters/schemas.ts#L29

[team-schema]: https://github.com/fchauvel/rpp/blob/058f1722d116955bb9a018dcca6287a926044670/src/storage/adapters/schemas.ts#L111
25 changes: 25 additions & 0 deletions samples/erroneous/syntax/workplan.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#
# Copyright (C) 2019, 2020 Franck Chauvel
# All rights reserved.
#
# This software may be modified and distributed under the terms
# of the MIT license.
#
# See the LICENSE file for details.
#

project:
name: Erroneous
origin: "2020-09-16"
breakdown:
- name: First Tasks
start: 5
duration: 7
coolstuff: Stufff!
# Empty work package
- name: First Package
breakdown: []
milestones:
# Milestone after project
- name: First milestone
date: 18
4 changes: 2 additions & 2 deletions src/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { Blueprint, RPP } from "./rpp";
import { FileSystem, Storage } from "./storage";
import { Terminal } from "./terminal";

import { Report as SyntaxError } from "@fchauvel/quick-check/dist/issues"
import { Report as SyntaxError } from "@fchauvel/quick-check/dist/issues";


interface Arguments {
Expand Down Expand Up @@ -176,7 +176,7 @@ export class Controller {
private loadBlueprint(args: Arguments): Blueprint {
const project = this._storage.loadProject(args.project);
let team;
if (args.team) {
if (args.team) {
team = this._storage.loadTeam(args.team);
}
return new Blueprint(project, team);
Expand Down
18 changes: 9 additions & 9 deletions src/storage/adapters/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import { anArrayOf,
anObject,
aProperty,
aString,
eitherOf } from "@fchauvel/quick-check";
eitherOf } from "@fchauvel/quick-check";

import { Partner, Person, Role, Team } from "../../rpp/team";
import { Deliverable, Milestone, Project, Task, Package } from "../../rpp/wbs";
import { Person, Role, Team } from "../../rpp/team";
import { Deliverable, Milestone, Package, Project, Task } from "../../rpp/wbs";
import { Path } from "../../rpp/wbs";


Expand Down Expand Up @@ -75,19 +75,19 @@ workPlanSchema.on("project")
data.name,
data.breakdown,
new Date(data.origin),
data.milestones
data.milestones,
));

workPlanSchema.on("milestone")
.apply((data) => new Milestone(
data.name,
data.date
data.date,
));

workPlanSchema.on("work package")
.apply((data) => new Package(
data.name,
data.breakdown
data.breakdown,
));

workPlanSchema.on("task")
Expand Down Expand Up @@ -145,14 +145,14 @@ teamSchema.on("team")
teamSchema.on("person")
.apply( (data) => {
const roles = data.contributes.map(
activity => Role.contributeTo(activity)
(activity) => Role.contributeTo(activity),
);
data.leads.forEach(
activity => roles.push(Role.lead(activity))
(activity) => roles.push(Role.lead(activity)),
);
return new Person(data.firstname,
data.lastname,
roles)
roles);
});

teamSchema.on("task-reference")
Expand Down
2 changes: 1 addition & 1 deletion src/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class Terminal {
}


public unexpectedError(error: any): void {
public unexpectedError(error: unknown): void {
this.write(error.toString());
}

Expand Down
48 changes: 48 additions & 0 deletions tests/acceptance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,51 @@ describe("Given the 'Erroneous' sample", () => {
});

});


describe("Given a file that does not exist", () => {

const tester = new Acceptance();

test("'rpp verify' not throw an error", () => {
expect(() => {
tester.invoke(["rpp", "verify",
"-p", "this/file/does_not.exist" ]);
}).not.toThrow();
});


test("'rpp gantt' should not throw an error", () => {
expect(() => {
tester.invoke(["rpp", "gantt",
"-p", "this/file/does_not.exist",
"-o", "gantt.svg"]);
}).not.toThrow();
});


});


describe("Given a file that does not adhere to the schema", () => {

const tester = new Acceptance();

test("'rpp verify' should not throw an error", () => {
expect(() => {
tester.invoke(
["rpp", "verify",
"-p", "samples/erroneous/syntax/workplan.yaml"]);
}).not.toThrow();
});

test("'rpp gantt' should not throw an error", () => {
expect(() => {
tester.invoke(
["rpp", "gantt",
"-p", "samples/erroneous/syntax/workplan.yaml",
"-o", "gantt.svg"]);
}).not.toThrow();
});

});
6 changes: 3 additions & 3 deletions tests/sample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@


import { Blueprint } from "../src/rpp";
import { teamSchema, workPlanSchema } from "../src/storage/adapters/schemas"
import { teamSchema, workPlanSchema } from "../src/storage/adapters/schemas";

import * as fs from "fs";


export interface JsonBlueprint {
project: any;
team: any;
project: unknown;
team: unknown;
}


Expand Down

0 comments on commit d6ffa92

Please sign in to comment.