Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add tests for series creator achievements #678

Merged
merged 3 commits into from
Aug 16, 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
46 changes: 46 additions & 0 deletions data/test-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,35 @@ export const sprinterAttribs = {
name: 'Sprinter'
};


export const seriesCreatorIAttribs = {
badgeUrl: 'http://test.com',
description: 'create 1 series',
id: 1,
name: 'Series Creator I'
};

export const seriesCreatorIIAttribs = {
badgeUrl: 'http://test.com',
description: 'create 10 series',
id: 2,
name: 'Series Creator II'
};

export const seriesCreatorIIIAttribs = {
badgeUrl: 'http://test.com',
description: 'create 100 series',
id: 3,
name: 'Series Creator III'
};

export const seriesCreatorAttribs = {
description: 'finish series creator track',
id: 1,
title: 'Series Creator'
};


export const workerBeeIAttribs = {
badgeUrl: 'http://test.com',
description: 'create 1 work',
Expand Down Expand Up @@ -386,6 +415,23 @@ export function createWorkerBee() {
);
}

export function createSeriesCreator() {
return new AchievementType(seriesCreatorIAttribs)
.save(null, {method: 'insert'})
.then(
() => new AchievementType(seriesCreatorIIAttribs)
.save(null, {method: 'insert'})
)
.then(
() => new AchievementType(seriesCreatorIIIAttribs)
.save(null, {method: 'insert'})
)
.then(
() => new TitleType(seriesCreatorAttribs)
.save(null, {method: 'insert'})
);
}

export function createPublisherCreator() {
return new AchievementType(publisherCreatorIAttribs)
.save(null, {method: 'insert'})
Expand Down
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);
}