Skip to content

Commit

Permalink
test(85% Coverage):
Browse files Browse the repository at this point in the history
- Get test coverage up to 85%
  • Loading branch information
Matt Potts committed Feb 3, 2021
1 parent 0e691e9 commit 31b11d7
Show file tree
Hide file tree
Showing 17 changed files with 234 additions and 37 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
/node_modules/
/npm-debug.log
/package-lock.json
/package-lock.json
/.nyc_output/
1 change: 1 addition & 0 deletions .idea/fabricate.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/packs/fabricate-test.db
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{"name":"Mud","permission":{"default":0,"fodYLey8TVAHJWcf":3},"type":"consumable","data":{"description":{"value":"","chat":"","unidentified":""},"source":"Fabricate: Test","quantity":1,"weight":0,"price":0,"attuned":false,"attunement":0,"equipped":false,"rarity":"","identified":true,"activation":{"type":"","cost":0,"condition":""},"duration":{"value":null,"units":""},"target":{"value":null,"width":null,"units":"","type":""},"range":{"value":null,"long":null,"units":""},"uses":{"value":0,"max":0,"per":null,"autoDestroy":false},"consume":{"type":"","target":null,"amount":null},"ability":null,"actionType":"","attackBonus":0,"chatFlavor":"","critical":null,"damage":{"parts":[],"versatile":""},"formula":"","save":{"ability":"","dc":null,"scaling":"spell"},"consumableType":"potion"},"flags":{"fabricate":{"type":"COMPONENT","component":{"name":"Mud","compendiumEntry":{"compendiumKey":"fabricate.fabricate-test","entryId":"tCmAnq9zcESt0ULf"}}}},"img":"systems/dnd5e/icons/items/inventory/herb-bag.jpg","effects":[],"_id":"tCmAnq9zcESt0ULf"}
{"name":"Sticks","permission":{"default":0,"fodYLey8TVAHJWcf":3},"type":"consumable","data":{"description":{"value":"","chat":"","unidentified":""},"source":"Fabricate: Test","quantity":1,"weight":0,"price":0,"attuned":false,"attunement":0,"equipped":false,"rarity":"","identified":true,"activation":{"type":"","cost":0,"condition":""},"duration":{"value":null,"units":""},"target":{"value":null,"width":null,"units":"","type":""},"range":{"value":null,"long":null,"units":""},"uses":{"value":0,"max":0,"per":null,"autoDestroy":false},"consume":{"type":"","target":null,"amount":null},"ability":null,"actionType":"","attackBonus":0,"chatFlavor":"","critical":null,"damage":{"parts":[],"versatile":""},"formula":"","save":{"ability":"","dc":null,"scaling":"spell"},"consumableType":"potion"},"flags":{"fabricate":{"type":"COMPONENT","component":{"name":"Sticks","compendiumEntry":{"compendiumKey":"fabricate.fabricate-test","entryId":"arWeEYkLkubimBz3"}}}},"img":"systems/dnd5e/icons/items/inventory/herb-bag.jpg","effects":[],"_id":"arWeEYkLkubimBz3"}
{"name":"Recipe: Mud Pie","permission":{"default":0,"fodYLey8TVAHJWcf":3},"type":"consumable","data":{"description":{"value":"","chat":"","unidentified":""},"source":"Fabricate: Test","quantity":1,"weight":0,"price":0,"attuned":false,"attunement":0,"equipped":false,"rarity":"","identified":true,"activation":{"type":"","cost":0,"condition":""},"duration":{"value":null,"units":""},"target":{"value":null,"width":null,"units":"","type":""},"range":{"value":null,"long":null,"units":""},"uses":{"value":0,"max":0,"per":null,"autoDestroy":false},"consume":{"type":"","target":null,"amount":null},"ability":null,"actionType":"","attackBonus":0,"chatFlavor":"","critical":null,"damage":{"parts":[],"versatile":""},"formula":"","save":{"ability":"","dc":null,"scaling":"spell"},"consumableType":"potion"},"flags":{"fabricate":{"type":"RECIPE","recipe":{"itemId":"4iHqWSLTMFjPbpuI","name":"Recipe: Mud Pie","ingredients":[{"componentType":{"name":"Mud","compendiumEntry":{"compendiumKey":"fabricate.fabricate-test","entryId":"tCmAnq9zcESt0ULf"}},"quantity":2,"consumed":true},{"componentType":{"name":"Sticks","compendiumEntry":{"compendiumKey":"fabricate.fabricate-test","entryId":"arWeEYkLkubimBz3"}},"quantity":1,"consumed":true}],"results":[{"action":"ADD","item":{"name":"Mud Pie","compendiumEntry":{"compendiumKey":"fabricate.fabricate-test","entryId":"nWhTa8gD1QL1f9O3"}},"quantity":1}]}}},"img":"systems/dnd5e/icons/items/inventory/paper.jpg","effects":[],"_id":"4iHqWSLTMFjPbpuI"}
{"name":"Recipe: Mud Pie","permission":{"default":0,"fodYLey8TVAHJWcf":3},"type":"consumable","data":{"description":{"value":"","chat":"","unidentified":""},"source":"Fabricate: Test","quantity":1,"weight":0,"price":0,"attuned":false,"attunement":0,"equipped":false,"rarity":"","identified":true,"activation":{"type":"","cost":0,"condition":""},"duration":{"value":null,"units":""},"target":{"value":null,"width":null,"units":"","type":""},"range":{"value":null,"long":null,"units":""},"uses":{"value":0,"max":0,"per":null,"autoDestroy":false},"consume":{"type":"","target":null,"amount":null},"ability":null,"actionType":"","attackBonus":0,"chatFlavor":"","critical":null,"damage":{"parts":[],"versatile":""},"formula":"","save":{"ability":"","dc":null,"scaling":"spell"},"consumableType":"potion"},"flags":{"fabricate":{"type":"RECIPE","recipe":{"entryId":"4iHqWSLTMFjPbpuI","name":"Recipe: Mud Pie","ingredients":[{"componentType":{"name":"Mud","compendiumEntry":{"compendiumKey":"fabricate.fabricate-test","entryId":"tCmAnq9zcESt0ULf"}},"quantity":2,"consumed":true},{"componentType":{"name":"Sticks","compendiumEntry":{"compendiumKey":"fabricate.fabricate-test","entryId":"arWeEYkLkubimBz3"}},"quantity":1,"consumed":true}],"results":[{"action":"ADD","item":{"name":"Mud Pie","compendiumEntry":{"compendiumKey":"fabricate.fabricate-test","entryId":"nWhTa8gD1QL1f9O3"}},"quantity":1}]}}},"img":"systems/dnd5e/icons/items/inventory/paper.jpg","effects":[],"_id":"4iHqWSLTMFjPbpuI"}
{"name":"Mud Pie","permission":{"default":0,"fodYLey8TVAHJWcf":3},"type":"consumable","data":{"description":{"value":"","chat":"","unidentified":""},"source":"Fabricate: Test","quantity":1,"weight":0,"price":0,"attuned":false,"attunement":0,"equipped":false,"rarity":"","identified":false,"activation":{"type":"","cost":0,"condition":""},"duration":{"value":null,"units":""},"target":{"value":null,"width":null,"units":"","type":""},"range":{"value":null,"long":null,"units":""},"uses":{"value":0,"max":0,"per":null,"autoDestroy":false},"consume":{"type":"","target":null,"amount":null},"ability":null,"actionType":"","attackBonus":0,"chatFlavor":"","critical":null,"damage":{"parts":[],"versatile":""},"formula":"","save":{"ability":"","dc":null,"scaling":"spell"},"consumableType":"potion"},"flags":{"fabricate":{"type":"COMPONENT","component":{"name":"Mud Pie","compendiumEntry":{"compendiumKey":"fabricate.fabricate-test","entryId":"4iHqWSLTMFjPbpuI"}}}},"img":"systems/dnd5e/icons/items/inventory/soup.jpg","effects":[],"_id":"nWhTa8gD1QL1f9O3"}
10 changes: 5 additions & 5 deletions dist/scripts/module.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"gulp-typescript": "^6.0.0-alpha.1",
"gulp-webpack": "^1.5.0",
"mocha": "^6.2.3",
"nyc": "^15.1.0",
"sinon": "^9.2.4",
"ts-loader": "^8.0.14",
"ts-node": "^9.1.1",
Expand Down
2 changes: 1 addition & 1 deletion src/packs/fabricate-test.db
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{"name":"Mud","permission":{"default":0,"fodYLey8TVAHJWcf":3},"type":"consumable","data":{"description":{"value":"","chat":"","unidentified":""},"source":"Fabricate: Test","quantity":1,"weight":0,"price":0,"attuned":false,"attunement":0,"equipped":false,"rarity":"","identified":true,"activation":{"type":"","cost":0,"condition":""},"duration":{"value":null,"units":""},"target":{"value":null,"width":null,"units":"","type":""},"range":{"value":null,"long":null,"units":""},"uses":{"value":0,"max":0,"per":null,"autoDestroy":false},"consume":{"type":"","target":null,"amount":null},"ability":null,"actionType":"","attackBonus":0,"chatFlavor":"","critical":null,"damage":{"parts":[],"versatile":""},"formula":"","save":{"ability":"","dc":null,"scaling":"spell"},"consumableType":"potion"},"flags":{"fabricate":{"type":"COMPONENT","component":{"name":"Mud","compendiumEntry":{"compendiumKey":"fabricate.fabricate-test","entryId":"tCmAnq9zcESt0ULf"}}}},"img":"systems/dnd5e/icons/items/inventory/herb-bag.jpg","effects":[],"_id":"tCmAnq9zcESt0ULf"}
{"name":"Sticks","permission":{"default":0,"fodYLey8TVAHJWcf":3},"type":"consumable","data":{"description":{"value":"","chat":"","unidentified":""},"source":"Fabricate: Test","quantity":1,"weight":0,"price":0,"attuned":false,"attunement":0,"equipped":false,"rarity":"","identified":true,"activation":{"type":"","cost":0,"condition":""},"duration":{"value":null,"units":""},"target":{"value":null,"width":null,"units":"","type":""},"range":{"value":null,"long":null,"units":""},"uses":{"value":0,"max":0,"per":null,"autoDestroy":false},"consume":{"type":"","target":null,"amount":null},"ability":null,"actionType":"","attackBonus":0,"chatFlavor":"","critical":null,"damage":{"parts":[],"versatile":""},"formula":"","save":{"ability":"","dc":null,"scaling":"spell"},"consumableType":"potion"},"flags":{"fabricate":{"type":"COMPONENT","component":{"name":"Sticks","compendiumEntry":{"compendiumKey":"fabricate.fabricate-test","entryId":"arWeEYkLkubimBz3"}}}},"img":"systems/dnd5e/icons/items/inventory/herb-bag.jpg","effects":[],"_id":"arWeEYkLkubimBz3"}
{"name":"Recipe: Mud Pie","permission":{"default":0,"fodYLey8TVAHJWcf":3},"type":"consumable","data":{"description":{"value":"","chat":"","unidentified":""},"source":"Fabricate: Test","quantity":1,"weight":0,"price":0,"attuned":false,"attunement":0,"equipped":false,"rarity":"","identified":true,"activation":{"type":"","cost":0,"condition":""},"duration":{"value":null,"units":""},"target":{"value":null,"width":null,"units":"","type":""},"range":{"value":null,"long":null,"units":""},"uses":{"value":0,"max":0,"per":null,"autoDestroy":false},"consume":{"type":"","target":null,"amount":null},"ability":null,"actionType":"","attackBonus":0,"chatFlavor":"","critical":null,"damage":{"parts":[],"versatile":""},"formula":"","save":{"ability":"","dc":null,"scaling":"spell"},"consumableType":"potion"},"flags":{"fabricate":{"type":"RECIPE","recipe":{"itemId":"4iHqWSLTMFjPbpuI","name":"Recipe: Mud Pie","ingredients":[{"componentType":{"name":"Mud","compendiumEntry":{"compendiumKey":"fabricate.fabricate-test","entryId":"tCmAnq9zcESt0ULf"}},"quantity":2,"consumed":true},{"componentType":{"name":"Sticks","compendiumEntry":{"compendiumKey":"fabricate.fabricate-test","entryId":"arWeEYkLkubimBz3"}},"quantity":1,"consumed":true}],"results":[{"action":"ADD","item":{"name":"Mud Pie","compendiumEntry":{"compendiumKey":"fabricate.fabricate-test","entryId":"nWhTa8gD1QL1f9O3"}},"quantity":1}]}}},"img":"systems/dnd5e/icons/items/inventory/paper.jpg","effects":[],"_id":"4iHqWSLTMFjPbpuI"}
{"name":"Recipe: Mud Pie","permission":{"default":0,"fodYLey8TVAHJWcf":3},"type":"consumable","data":{"description":{"value":"","chat":"","unidentified":""},"source":"Fabricate: Test","quantity":1,"weight":0,"price":0,"attuned":false,"attunement":0,"equipped":false,"rarity":"","identified":true,"activation":{"type":"","cost":0,"condition":""},"duration":{"value":null,"units":""},"target":{"value":null,"width":null,"units":"","type":""},"range":{"value":null,"long":null,"units":""},"uses":{"value":0,"max":0,"per":null,"autoDestroy":false},"consume":{"type":"","target":null,"amount":null},"ability":null,"actionType":"","attackBonus":0,"chatFlavor":"","critical":null,"damage":{"parts":[],"versatile":""},"formula":"","save":{"ability":"","dc":null,"scaling":"spell"},"consumableType":"potion"},"flags":{"fabricate":{"type":"RECIPE","recipe":{"entryId":"4iHqWSLTMFjPbpuI","name":"Recipe: Mud Pie","ingredients":[{"componentType":{"name":"Mud","compendiumEntry":{"compendiumKey":"fabricate.fabricate-test","entryId":"tCmAnq9zcESt0ULf"}},"quantity":2,"consumed":true},{"componentType":{"name":"Sticks","compendiumEntry":{"compendiumKey":"fabricate.fabricate-test","entryId":"arWeEYkLkubimBz3"}},"quantity":1,"consumed":true}],"results":[{"action":"ADD","item":{"name":"Mud Pie","compendiumEntry":{"compendiumKey":"fabricate.fabricate-test","entryId":"nWhTa8gD1QL1f9O3"}},"quantity":1}]}}},"img":"systems/dnd5e/icons/items/inventory/paper.jpg","effects":[],"_id":"4iHqWSLTMFjPbpuI"}
{"name":"Mud Pie","permission":{"default":0,"fodYLey8TVAHJWcf":3},"type":"consumable","data":{"description":{"value":"","chat":"","unidentified":""},"source":"Fabricate: Test","quantity":1,"weight":0,"price":0,"attuned":false,"attunement":0,"equipped":false,"rarity":"","identified":false,"activation":{"type":"","cost":0,"condition":""},"duration":{"value":null,"units":""},"target":{"value":null,"width":null,"units":"","type":""},"range":{"value":null,"long":null,"units":""},"uses":{"value":0,"max":0,"per":null,"autoDestroy":false},"consume":{"type":"","target":null,"amount":null},"ability":null,"actionType":"","attackBonus":0,"chatFlavor":"","critical":null,"damage":{"parts":[],"versatile":""},"formula":"","save":{"ability":"","dc":null,"scaling":"spell"},"consumableType":"potion"},"flags":{"fabricate":{"type":"COMPONENT","component":{"name":"Mud Pie","compendiumEntry":{"compendiumKey":"fabricate.fabricate-test","entryId":"4iHqWSLTMFjPbpuI"}}}},"img":"systems/dnd5e/icons/items/inventory/soup.jpg","effects":[],"_id":"nWhTa8gD1QL1f9O3"}
2 changes: 1 addition & 1 deletion src/scripts/core/CraftingInventory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ abstract class CraftingInventory implements Inventory {
});
if (duplicatedIngredient) {
throw new Error(`One or more ingredients were duplicated in a call to CraftingInventory.containsMany(ingredients: Ingredient[]).
Recipe[name='${recipe.name}',id='${recipe.itemId}'] seems to be misconfigured! Recipes should be specified as
Recipe[name='${recipe.name}',id='${recipe.entryId}'] seems to be misconfigured! Recipes should be specified as
Ingredient[Mud, 2], not [Ingredient[Mud, 1], Ingredient[Mud 1]]. `);
}
return !failedToFind;
Expand Down
13 changes: 7 additions & 6 deletions src/scripts/core/CraftingSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class CraftingSystem {
return this._name;
}

public async craft(actorId: string, recipeId: string) {
public async craft(actorId: string, recipeId: string): Promise<CraftingResult[]> {
const inventory: Inventory = InventoryRegistry.getFor(actorId);
const recipe: Recipe = this._recipes.find((recipe: Recipe) => recipe.itemId == recipeId);
const recipe: Recipe = this._recipes.find((recipe: Recipe) => recipe.entryId == recipeId);

const missingIngredients: Ingredient[] = [];
recipe.components.forEach((ingredient: Ingredient) => {
Expand All @@ -50,23 +50,24 @@ class CraftingSystem {

const fabricator: Fabricator = this.fabricator;
const craftingResults: CraftingResult[] = fabricator.fabricateFromRecipe(recipe);
const results: Promise<InventoryRecord|boolean>[] = [];
const inventoryActions: Promise<InventoryRecord|boolean>[] = [];
craftingResults.forEach((craftingResult: CraftingResult) => {
switch (craftingResult.action) {
case ActionType.ADD:
const add = inventory.add(craftingResult.item, craftingResult.quantity);
results.push(add);
inventoryActions.push(add);
break;
case ActionType.REMOVE:
const remove = inventory.remove(craftingResult.item, craftingResult.quantity);
results.push(remove);
inventoryActions.push(remove);
break;
default:
throw new Error(`The Crafting Action Type ${craftingResult.action} is not supported. Allowable
values are: ADD, REMOVE. `);
}
});
return Promise.all(results);
await Promise.all(inventoryActions);
return craftingResults;
}

get compendiumPackKey(): string {
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/core/FabricateFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interface ResultFlags {
interface FabricateFlags {
type: FabricateItemType;
recipe?: {
itemId: string,
entryId: string,
name: string,
ingredients: IngredientFlags[],
results: ResultFlags[]
Expand Down
16 changes: 8 additions & 8 deletions src/scripts/core/Recipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ class Recipe {
private readonly _components: Ingredient[];
private readonly _results: CraftingResult[];
private readonly _name: string;
private readonly _itemId: string;
private readonly _entryId: string;

constructor(builder: Recipe.Builder) {
this._components = builder.ingredients;
this._results = builder.results;
this._name = builder.name;
this._itemId = builder.itemId;
this._entryId = builder.entryId;
}

public static fromFlags(flags: FabricateFlags): Recipe {
Expand All @@ -21,7 +21,7 @@ class Recipe {
}
return Recipe.builder()
.withName(flags.recipe.name)
.withItemId(flags.recipe.itemId)
.withEntryId(flags.recipe.entryId)
.withResults(CraftingResult.manyFromFlags(flags.recipe.results))
.withIngredients(Ingredient.manyFromFlags(flags.recipe.ingredients))
.build();
Expand All @@ -40,8 +40,8 @@ class Recipe {
}


get itemId(): string {
return this._itemId;
get entryId(): string {
return this._entryId;
}

public static builder() {
Expand All @@ -54,7 +54,7 @@ namespace Recipe {
public ingredients: Ingredient[] = [];
public results: CraftingResult[] = [];
public name!: string;
public itemId!: string;
public entryId!: string;

public build() {
return new Recipe(this);
Expand Down Expand Up @@ -85,8 +85,8 @@ namespace Recipe {
return this;
}

withItemId(value: string) {
this.itemId = value;
withEntryId(value: string) {
this.entryId = value;
return this;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/systems/CraftingSystemRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class CraftingSystemRegistry {

private static resolveRecipesForSystem(system: CraftingSystem): void {
system.recipes.forEach((recipe: Recipe) => {
CraftingSystemRegistry.craftingSystemsByRecipeId.set(recipe.itemId, system);
CraftingSystemRegistry.craftingSystemsByRecipeId.set(recipe.entryId, system);
});
}

Expand Down
Loading

0 comments on commit 31b11d7

Please sign in to comment.