Skip to content

Commit

Permalink
test: add test for series creator achievements
Browse files Browse the repository at this point in the history
  • Loading branch information
akashgp09 committed Jul 22, 2021
1 parent ca3cd78 commit 199aa60
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
2 changes: 2 additions & 0 deletions test/test-achievement.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import testMarathoner from './test-marathoner.js';
import testPublisher from './test-publisher.js';
import testPublisherCreator from './test-publisher-creator.js';
import testRevisionist from './test-revisionist.js';
import testSeriesCreator from './test-series-creator.js';
import testSprinter from './test-sprinter.js';
import testTimeTraveller from './test-time-traveller.js';
import testWorkerBee from './test-worker-bee.js';
Expand Down Expand Up @@ -171,6 +172,7 @@ function tests() {
describe('Revisionist Achievement', testRevisionist);
describe('Sprinter Achievement', testSprinter);
describe('Time Traveller Achievement', testTimeTraveller);
describe('Series Creator Achievement', testSeriesCreator);
describe('Worker Bee Achievement', testWorkerBee);
}

Expand Down
84 changes: 84 additions & 0 deletions test/test-series-creator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright (C) 2021 Akash Gupta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

import * as common from './common';
import * as testData from '../data/test-data.js';
import orm from './bookbrainz-data';
import rewire from 'rewire';


const Achievement = rewire('../src/server/helpers/achievement.js');

const thresholdI = 1;
const thresholdII = 10;
const thresholdIII = 100;

function rewireTypeCreation(threshold) {
return common.rewireTypeCreation(Achievement, 'series', threshold);
}

function getAttrPromise() {
return common.getAttrPromise(Achievement, orm, true, 'seriesCreator');
}

function getRevAttrPromise(rev) {
return common.getAttrPromise(
Achievement, orm, true, 'seriesCreator', `Series Creator ${rev}`
);
}

function expectIds(rev) {
return common.expectIds('seriesCreator', rev);
}

function expectAllNamedIds(rev) {
return common.expectAllNamedIds('Series Creator', 'seriesCreator', rev);
}

export default function tests() {
beforeEach(() => testData.createSeriesCreator());
afterEach(testData.truncate);

const test1 = common.testAchievement(
rewireTypeCreation(thresholdI),
getRevAttrPromise('I'),
expectIds('I')
);
it('I should be given to someone with a series creation', test1);

const test2 = common.testAchievement(
rewireTypeCreation(thresholdII),
getRevAttrPromise('II'),
expectIds('II')
);
it('II should be given to someone with 10 series creations', test2);

const test3 = common.testAchievement(
rewireTypeCreation(thresholdIII),
getAttrPromise(),
expectAllNamedIds('III')
);
it('III should be given to someone with 100 series creations', test3);

const test4 = common.testAchievement(
rewireTypeCreation(0),
getRevAttrPromise('I'),
common.expectFalse()
);
it('should not be given to someone with 0 series creations', test4);
}

0 comments on commit 199aa60

Please sign in to comment.