Skip to content
This repository has been archived by the owner on Jan 12, 2023. It is now read-only.

fix: migrate to ava for tests #60

Merged
merged 1 commit into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7,172 changes: 4,358 additions & 2,814 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
"scripts": {
"lint": "eslint .",
"fix-lint": "eslint . --fix",
"test": "nyc --reporter=lcov tape test/**/*.js | tap-spec && nyc report",
"test": "nyc ava",
"build-cached-mods": "node -e 'require(\"./src/util/build-cached-mods.js\").printCachedMods()'",
"build-cached-exotics": "node -e 'require(\"./src/util/build-cached-exotics.js\").printCachedExotics()'",
"build": "npm install --production && rm -rf build && mkdir build && zip -r -q -x='*test*' -x='package-lock.json' -x='*media*' -x='*terraform*' -x=*coverage* -x='*.md' -x='LICENSE' -x='*build*' -x='*.DS_Store*' -x='*.git*' -x='release.config.js' -x='commitlint.config.js' build/destiny-insights-backend.zip . && du -sh build",
"deploy": "aws lambda update-function-code --function-name=destiny-insights-backend --zip-file=fileb://build/destiny-insights-backend.zip --region=us-east-1 1> /dev/null",
"semantic-release": "semantic-release",
"ci": "npm run lint && npm run test",
"cd": "npm run build && npm run deploy"
"cd": "npm run build && npm run deploy",
"prepare": "husky install"
},
"contributors": [
{
Expand Down Expand Up @@ -45,15 +46,14 @@
"@semantic-release/github": "~7.2.3",
"@semantic-release/npm": "~7.1.3",
"@semantic-release/release-notes-generator": "~9.0.3",
"aws-sdk": "~2.943.0",
"ava": "~3.15.0",
"aws-sdk": "~2.950.0",
"commitizen": "~4.2.4",
"cz-conventional-changelog": "~3.3.0",
"eslint": "~7.30.0",
"husky": "~4.3.8",
"eslint": "~7.31.0",
"husky": "~7.0.1",
"nyc": "~15.1.0",
"semantic-release": "^17.4.4",
"tap-spec": "~5.0.0",
"tape-async": "~2.3.0"
"semantic-release": "~17.4.4"
},
"husky": {
"hooks": {
Expand Down
17 changes: 6 additions & 11 deletions test/integration/build-cached-exotics.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
const test = require("tape-async")
const test = require("ava")
const { buildCachedExotics } = require("../../src/util/build-cached-exotics.js")

test("Integration - buildCachedExotics", async (assert) => {
assert.plan(3)
test("Integration - buildCachedExotics for exotic", async (assert) => {
const cachedMods = await buildCachedExotics()
const wormhuskCrown = cachedMods["3562696927"]
const name = wormhuskCrown.name
const type = wormhuskCrown.type
const icon = wormhuskCrown.icon
assert.equal(name, "Wormhusk Crown", "buildCachedExotics for weapon mod name verified")
assert.equal(type, "Exotic Helmet", "buildCachedExotics for weapon mod type verified")
const { name, type, icon } = cachedMods["3562696927"]
assert.is(name, "Wormhusk Crown")
assert.is(type, "Exotic Helmet")
// eslint-disable-next-line max-len
const expectedIconPath = "https://bungie.net/common/destiny2_content/icons/95eb480d723f510afd9fd3e2bbb1d92d.jpg"
assert.equal(icon, expectedIconPath, "buildCachedExotics for weapon mod icon path verified")
assert.is(icon, "https://bungie.net/common/destiny2_content/icons/95eb480d723f510afd9fd3e2bbb1d92d.jpg")
})
21 changes: 7 additions & 14 deletions test/integration/build-cached-mods.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
const test = require("tape-async")
const test = require("ava")
const { buildCachedMods } = require("../../src/util/build-cached-mods.js")

test("Integration - buildCachedMods", async (assert) => {
assert.plan(4)
test("Integration - buildCachedMods for weapon mod", async (assert) => {
const cachedMods = await buildCachedMods()
const rampageSpec = cachedMods["666440382"]
const name = rampageSpec.name
const type = rampageSpec.type
const description = rampageSpec.description
const icon = rampageSpec.icon
assert.equal(name, "Rampage Spec", "buildCachedMods for weapon mod name verified")
assert.equal(type, "Legendary Weapon Mod", "buildCachedMods for weapon mod type verified")
const { name, type, description, icon } = cachedMods["666440382"]
assert.is(name, "Rampage Spec")
assert.is(type, "Legendary Weapon Mod")
assert.is(description, "Increases duration of Rampage.")
// eslint-disable-next-line max-len
assert.equal(description, "Increases duration of Rampage.", "buildCachedMods for weapon mod description verified")
// eslint-disable-next-line max-len
const expectedIconPath = "https://bungie.net/common/destiny2_content/icons/b3eadd1fcadf34e389fad3e7a75acc26.jpg"
assert.equal(icon, expectedIconPath, "buildCachedMods for weapon mod icon path verified")
assert.is(icon, "https://bungie.net/common/destiny2_content/icons/b3eadd1fcadf34e389fad3e7a75acc26.jpg")
})
18 changes: 9 additions & 9 deletions test/unit/check-if-token-refresh-needed.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
const test = require("tape-async")
const test = require("ava")
const { checkIfTokenRefreshNeeded } = require("../../src/util/check-if-token-refresh-needed.js")

test("Unit - checkIfTokenRefreshNeeded", async (assert) => {
assert.plan(2)
test("Unit - checkIfTokenRefreshNeeded no refresh needed", async (assert) => {
const now = new Date()
let result = checkIfTokenRefreshNeeded({ lastTokenRefresh: now, expiresIn: 3600 })
let expected = false
assert.equal(result, expected, "checkIfTokenRefreshNeeded no refresh needed verified")
const result = checkIfTokenRefreshNeeded({ lastTokenRefresh: now, expiresIn: 3600 })
assert.false(result)
})

test("Unit - checkIfTokenRefreshNeeded refresh needed", async (assert) => {
const oneDayAgo = new Date()
oneDayAgo.setDate(oneDayAgo.getDate() - 1)
result = checkIfTokenRefreshNeeded({ lastTokenRefresh: oneDayAgo, expiresIn: 3600 })
expected = true
assert.equal(result, expected, "checkIfTokenRefreshNeeded refresh needed verified")
const result = checkIfTokenRefreshNeeded({ lastTokenRefresh: oneDayAgo, expiresIn: 3600 })
assert.true(result)
})
5 changes: 2 additions & 3 deletions test/unit/get-inventory-item-definition-endpoint.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const test = require("tape-async")
const test = require("ava")
// eslint-disable-next-line max-len
const { getInventoryItemDefinitionEndpoint } = require("../../src/util/get-inventory-item-definition-endpoint.js")

test("Unit - getInventoryItemDefinitionEndpoint", async (assert) => {
assert.plan(1)
const mockedManifestData = {
"Response": {
"jsonWorldComponentContentPaths": {
Expand All @@ -15,5 +14,5 @@ test("Unit - getInventoryItemDefinitionEndpoint", async (assert) => {
}
}
const inventoryItemDefinitionEndpoint = getInventoryItemDefinitionEndpoint(mockedManifestData)
assert.true(inventoryItemDefinitionEndpoint, "getInventoryItemDefinitionEndpoint verified")
assert.truthy(inventoryItemDefinitionEndpoint)
})
11 changes: 4 additions & 7 deletions test/unit/get-manifest.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
const test = require("tape-async")
const test = require("ava")
const { getManifest } = require("../../src/util/get-manifest.js")

test("Unit - getManifest", async (assert) => {
assert.plan(3)
const { manifest, manifestRetries } = await getManifest()
// eslint-disable-next-line max-len
assert.true(manifest.Response.jsonWorldComponentContentPaths.en.DestinyInventoryItemDefinition, "inventoryItemDefinitionEndpoint verified")
// eslint-disable-next-line max-len
assert.true(manifest.Response.jsonWorldComponentContentPaths.en.DestinySandboxPerkDefinition, "sandboxPerkDefinitionEndpoint verified")
assert.true(typeof manifestRetries === "number", "manifestRetries is a number verified")
assert.truthy(manifest.Response.jsonWorldComponentContentPaths.en.DestinyInventoryItemDefinition)
assert.truthy(manifest.Response.jsonWorldComponentContentPaths.en.DestinySandboxPerkDefinition)
assert.true(typeof manifestRetries === "number")
})
6 changes: 2 additions & 4 deletions test/unit/get-sandbox-perk-definition-endpoint.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const test = require("tape-async")
const test = require("ava")
// eslint-disable-next-line max-len
const { getSandboxPerkDefinitionEndpoint } = require("../../src/util/get-sandbox-perk-definition-endpoint.js")

test("Unit - getInventoryItemDefinitionEndpoint", async (assert) => {
assert.plan(1)
const mockedManifestData = {
"Response": {
"jsonWorldComponentContentPaths": {
Expand All @@ -15,6 +14,5 @@ test("Unit - getInventoryItemDefinitionEndpoint", async (assert) => {
}
}
const inventoryItemDefinitionEndpoint = getSandboxPerkDefinitionEndpoint(mockedManifestData)
// eslint-disable-next-line max-len
assert.true(inventoryItemDefinitionEndpoint, "getSandboxPerkDefinitionEndpoint verified")
assert.truthy(inventoryItemDefinitionEndpoint)
})