-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This will check all Quick Builds to make sure they use XWS ids that exist This will also make sure there are no duplicate pilot or upgrade XWS ids
- Loading branch information
1 parent
03fd9d1
commit e491b11
Showing
6 changed files
with
184 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,4 @@ cache: | |
yarn: true | ||
script: | ||
- yarn run validate:json | ||
- yarn run validate:schema | ||
- yarn run validate:tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
const manifest = require("../../data/manifest.json"); | ||
|
||
const loadedData = {}; | ||
const mapSlotXWSToName = { | ||
astromech: "Astromech", | ||
cannon: "Cannon", | ||
configuration: "Configuration", | ||
crew: "Crew", | ||
device: "Device", | ||
"force-power": "Force Power", | ||
gunner: "Gunner", | ||
illicit: "Illicit", | ||
missile: "Missile", | ||
modification: "Modification", | ||
sensor: "Sensor", | ||
tacticalrelay: "Tactical Relay", | ||
talent: "Talent", | ||
tech: "Tech", | ||
title: "Title", | ||
torpedo: "Torpedo", | ||
turret: "Turret" | ||
}; | ||
|
||
const loadPilotsAndShips = () => { | ||
const allPilots = []; | ||
const allShips = []; | ||
|
||
manifest.pilots.forEach(({ ships }) => { | ||
ships.forEach(filename => { | ||
const { pilots = [], ship } = require(`../../${filename}`); | ||
allPilots.push(...pilots); | ||
allShips.push(ship); | ||
}); | ||
}); | ||
|
||
return { ships: allShips, pilots: allPilots }; | ||
}; | ||
|
||
const getPilots = () => { | ||
if (!loadedData.pilots) { | ||
const { pilots } = loadPilotsAndShips(); | ||
loadedData.pilots = pilots; | ||
} | ||
return loadedData.pilots; | ||
}; | ||
|
||
const getPilotXWSIds = () => { | ||
const pilots = getPilots(); | ||
return pilots.map(p => p.xws).filter(Boolean); | ||
}; | ||
|
||
const validatePilotXWSId = id => { | ||
const ids = getPilotXWSIds(); | ||
if (ids.indexOf(id) === -1) { | ||
throw new Error(`Pilot xws id "${id}" does not exist`); | ||
} | ||
}; | ||
|
||
const loadUpgrades = () => { | ||
const allUpgrades = []; | ||
|
||
manifest.upgrades.forEach(filename => { | ||
const upgrades = require(`../../${filename}`); | ||
allUpgrades.push(...upgrades); | ||
}); | ||
|
||
return { upgrades: allUpgrades }; | ||
}; | ||
|
||
const getUpgrades = () => { | ||
if (!loadedData.upgrades) { | ||
const { upgrades } = loadUpgrades(); | ||
loadedData.upgrades = upgrades; | ||
} | ||
return loadedData.upgrades; | ||
}; | ||
|
||
const getUpgradesXWSIds = () => { | ||
const upgrades = getUpgrades(); | ||
return upgrades.map(u => u.xws).filter(Boolean); | ||
}; | ||
|
||
const getUpgradesXWSIdsForSlot = slotName => { | ||
const slotId = mapSlotXWSToName[slotName] || slotName; | ||
const upgrades = getUpgrades(); | ||
return upgrades | ||
.filter(u => u.sides.some(s => s.type === slotId)) | ||
.map(u => u.xws) | ||
.filter(Boolean); | ||
}; | ||
|
||
const validateUpgradeXWSIdForSlot = (id, slotName) => { | ||
const ids = getUpgradesXWSIdsForSlot(slotName); | ||
if (ids.indexOf(id) === -1) { | ||
throw new Error( | ||
`Upgrade xws id "${id}" does not exist for slot "${slotName}"` | ||
); | ||
} | ||
}; | ||
|
||
module.exports = { | ||
getPilotXWSIds, | ||
validatePilotXWSId, | ||
getUpgradesXWSIds, | ||
validateUpgradeXWSIdForSlot | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
const path = require("path"); | ||
const { | ||
validatePilotXWSId, | ||
validateUpgradeXWSIdForSlot | ||
} = require("./helpers/data"); | ||
const { matchers } = require("jest-json-schema"); | ||
expect.extend(matchers); | ||
|
||
const { "quick-builds": quickBuildFiles } = require("../data/manifest.json"); | ||
|
||
const quickBuildsSchema = require("./schemas/quick-build.schema.json"); | ||
|
||
describe("Quick Builds", () => { | ||
quickBuildFiles.forEach(file => { | ||
const contents = require(`../${file}`); | ||
|
||
test("has a top-level `quick-builds` property", () => { | ||
expect(contents).toHaveProperty("quick-builds"); | ||
}); | ||
|
||
// `data/quick-builds/resistance.json` -> `resistance` | ||
const faction = path.basename(file, path.extname(file)); | ||
|
||
describe(`${faction}`, () => { | ||
const { "quick-builds": quickBuilds } = contents; | ||
|
||
quickBuilds.forEach((qb, i) => { | ||
// Example: `#64 - threat 2 - deathrain` | ||
const testName = [ | ||
`#${i}`, | ||
`threat ${qb.threat}`, | ||
qb.pilots.map(d => d.id).join(", ") | ||
].join(" - "); | ||
|
||
describe(testName, () => { | ||
test("matches schema", () => { | ||
expect(qb).toMatchSchema(quickBuildsSchema); | ||
}); | ||
|
||
test("uses valid XWS ids", () => { | ||
qb.pilots.forEach(pilot => { | ||
const { id: pilotId, upgrades = {} } = pilot; | ||
validatePilotXWSId(pilotId); | ||
Object.entries(upgrades).forEach(([slot, ids]) => { | ||
ids.forEach(upgradeId => | ||
validateUpgradeXWSIdForSlot(upgradeId, slot) | ||
); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const { getPilotXWSIds, getUpgradesXWSIds } = require("./helpers/data"); | ||
|
||
const checkForDuplicates = ids => { | ||
ids.reduce((acc, id) => { | ||
if (acc.indexOf(id) > -1) { | ||
throw new Error(`Duplicate XWS id: "${id}"`); | ||
} | ||
acc.push(id); | ||
return acc; | ||
}, []); | ||
}; | ||
|
||
describe("XWS", () => { | ||
test("no duplicate pilot XWS ids", () => { | ||
checkForDuplicates(getPilotXWSIds()); | ||
}); | ||
test("no duplicate upgrade XWS ids", () => { | ||
checkForDuplicates(getUpgradesXWSIds()); | ||
}); | ||
}); |