-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding tests, minor refactor * test uninstallAddon() needs a better test * Smoke test for parsePage * version bump * moved test constants to mock.js * prep for merge to dev
- Loading branch information
Showing
21 changed files
with
358 additions
and
139 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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
8 changes: 4 additions & 4 deletions
8
src/checkWhichHost/__tests__/spec.js → src/__tests__/checkHost.spec.js
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
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,57 @@ | ||
import path from 'path' | ||
|
||
export const mockConfig = { | ||
addonDir: mockInstallDir, | ||
addonRecordFile: path.join(mockHomeDir, 'WorldOfAddons','addons.json'), | ||
checkUpdateOnStart: true | ||
} | ||
|
||
export const mockAddonObj = { | ||
"URL": "https://www.curseforge.com/wow/addons/a-good-wow-addon", | ||
"authors": [ | ||
"you-Are-Now-Breathing-Manually" | ||
], | ||
"displayName": "Wow Addon", | ||
"host": "curseforge", | ||
"name": "a-good-wow-addon", | ||
"status": "INSTALLED", | ||
"version": "1.0.0", | ||
"subdirs": [ | ||
"subdir0", | ||
"subdir1", | ||
"subdir2" | ||
] | ||
} | ||
|
||
export const mockInstallAddonsDict = { | ||
"a-good-wow-addon": { | ||
"URL": "https://www.curseforge.com/wow/addons/a-good-wow-addon", | ||
"authors": [ | ||
"you-Are-Now-Breathing-Manually" | ||
], | ||
"displayName": "Wow Addon0", | ||
"host": "curseforge", | ||
"name": "a-good-wow-addon", | ||
"status": "INSTALLED", | ||
"version": "1.0.0", | ||
"subdirs": [ | ||
"subdir1", | ||
"subdir2", | ||
"subdir3" | ||
] | ||
}, | ||
"another-wow-addon": { | ||
"URL": "https://www.curseforge.com/wow/addons/another-wow-addon", | ||
"authors": [ | ||
"you-Are-Now-Breathing-Manually" | ||
], | ||
"displayName": "Wow Addon1", | ||
"host": "curseforge", | ||
"name": "another-wow-addon", | ||
"status": "INSTALLED", | ||
"version": "999", | ||
"subdirs": [ | ||
"subdirOfWow Addon1" | ||
] | ||
} | ||
} |
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,28 @@ | ||
import { parseAddonDetails } from '../parsePage' | ||
|
||
describe('parseAddonDetails function', () => { | ||
describe('WHEN making a REAL request to curseforge.com', () => { | ||
describe('WHEN using a real URLObj for DBM hosted on Curseforge', () => { // TODO: Sometimes request fails, need to mock websocket and website | ||
it('THEN should return a valid addonObj', () => { | ||
const validURLObj = { 'url': 'https://www.curseforge.com/wow/addons/deadly-boss-mods', 'host': 'curseforge', 'name': 'deadly-boss-mods' } | ||
let promise = parseAddonDetails(validURLObj) | ||
return promise.then(result => { | ||
expect(result.displayName).toEqual('Deadly Boss Mods (DBM)') | ||
expect(result.name).toEqual('deadly-boss-mods') | ||
expect(result.version).not.toBeNull() | ||
expect(result.host).toEqual('curseforge') | ||
expect(result.url).toEqual('https://www.curseforge.com/wow/addons/deadly-boss-mods') | ||
expect(result.authors).toEqual(["mysticalos", "Tandanu", "DBM_Build", "Elnarfim", "Mini_Dragon", "Arta88", "Mave99", "nbluewiz", "oscarucb", "TOM_RUS", "SmoothMcGroove"]) | ||
expect(result.status).toEqual('') | ||
}) | ||
}) | ||
}) | ||
describe('WHEN using an invalid test URLObj', () => { | ||
it('THEN should return an error', () => { | ||
const invalidURLObj = { 'url': 'https://www.curseforge.com/wow/addons/test-addon', 'host': 'curseforge', 'name': 'test-addon' } | ||
let promise = parseAddonDetails(invalidURLObj) | ||
expect(promise).rejects.toThrow('Invalid URL.'); | ||
}) | ||
}) | ||
}) | ||
}) |
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,42 @@ | ||
import { mockAddonObj, mockConfig, mockInstallAddonsDict } from './mock' | ||
import { uninstallAddon } from '../uninstallAddon' | ||
import fs from 'fs' | ||
|
||
describe('uninstallAddon function', () => { | ||
describe('GIVEN a valid configObj', () => { | ||
describe('GIVEN a valid installAddonsDict', () => { | ||
describe('GIVEN a valid addonObj to be uninstalled', () => { | ||
describe('GIVEN an addon directory exists in the addon install directory', () => { | ||
// Needs to properly test function uninstallAddon(), this | ||
// requires something like simulating a filesystem in memory | ||
beforeEach(() => { | ||
fs.existsSync.mockReturnValue(true) | ||
fs.readdirSync.mockReturnValue(true) | ||
}) | ||
|
||
it('THEN should delete a-good-wow-addon from the addon dictionary and remove subdir0, subdir1 and subdir2', () => { | ||
let newDict = uninstallAddon(mockAddonObj, mockConfig, mockInstallAddonsDict) | ||
expect(newDict).toEqual({ | ||
"another-wow-addon": { | ||
"URL": "https://www.curseforge.com/wow/addons/another-wow-addon", | ||
"authors": [ | ||
"you-Are-Now-Breathing-Manually" | ||
], | ||
"displayName": "Wow Addon1", | ||
"host": "curseforge", | ||
"name": "another-wow-addon", | ||
"status": "INSTALLED", | ||
"version": "999", | ||
"subdirs": [ | ||
"subdirOfWow Addon1" | ||
] | ||
} | ||
}) | ||
}) | ||
}) | ||
|
||
}) | ||
|
||
}) | ||
}) | ||
}) |
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,18 @@ | ||
// Checks what website hosts the addon | ||
export function checkWhichHost (url) { | ||
if (url.startsWith('https://www.curseforge.com/wow/addons/')) { | ||
return initCurseforgeObj(url) | ||
} | ||
|
||
const errorObj = { 'error': `Invalid url '${url}'. Given link does not match parse` } | ||
return errorObj | ||
} | ||
|
||
// Creates a JSON object for addons hosted by Curseforge. | ||
// Parses the addon name from the end of the url, this name is how the | ||
// JSON object is referenced by other components | ||
function initCurseforgeObj (url) { | ||
const URLSplit = url.split('https://www.curseforge.com/wow/addons/') | ||
const URLObj = { 'url': url, 'host': 'curseforge', 'name': URLSplit[1] } | ||
return URLObj | ||
} |
Oops, something went wrong.