6161f94910
refs: https://github.com/TryGhost/Toolbox/issues/595 We're rolling out new rules around the node assert library, the first of which is enforcing the use of assert/strict. This means we don't need to use the strict version of methods, as the standard version will work that way by default. This caught some gotchas in our existing usage of assert where the lack of strict mode had unexpected results: - Url matching needs to be done on `url.href` seeaa58b354a4
- Null and undefined are not the same thing, there were a few cases of this being confused - Particularly questionable changes in [PostExporter tests](c1a468744b
) tracked [here](https://github.com/TryGhost/Team/issues/3505). - A typo seeeaac9c293a
Moving forward, using assert strict should help us to catch unexpected behaviour, particularly around nulls and undefineds during implementation.
98 lines
2.5 KiB
JavaScript
98 lines
2.5 KiB
JavaScript
const assert = require('assert/strict');
|
|
const TiersAPI = require('../lib/TiersAPI');
|
|
const InMemoryTierRepository = require('../lib/InMemoryTierRepository');
|
|
|
|
describe('TiersAPI', function () {
|
|
/** @type {TiersAPI.ITierRepository} */
|
|
let repository;
|
|
|
|
/** @type {TiersAPI} */
|
|
let api;
|
|
|
|
before(function () {
|
|
repository = new InMemoryTierRepository();
|
|
api = new TiersAPI({
|
|
repository,
|
|
slugService: {
|
|
async generate(input) {
|
|
return input;
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
it('Can not create new free Tiers', async function () {
|
|
let error;
|
|
try {
|
|
await api.add({
|
|
name: 'My testing Tier',
|
|
type: 'free'
|
|
});
|
|
error = null;
|
|
} catch (err) {
|
|
error = err;
|
|
} finally {
|
|
assert(error, 'An error should have been thrown');
|
|
}
|
|
});
|
|
|
|
it('Can create new paid Tiers and find them again', async function () {
|
|
const tier = await api.add({
|
|
name: 'My testing Tier',
|
|
type: 'paid',
|
|
monthlyPrice: 5000,
|
|
yearlyPrice: 50000,
|
|
currency: 'usd'
|
|
});
|
|
|
|
const found = await api.read(tier.id.toHexString());
|
|
|
|
assert(found);
|
|
});
|
|
|
|
it('Can edit a tier', async function () {
|
|
const tier = await api.add({
|
|
name: 'My testing Tier',
|
|
type: 'paid',
|
|
monthlyPrice: 5000,
|
|
yearlyPrice: 50000,
|
|
currency: 'usd'
|
|
});
|
|
|
|
const updated = await api.edit(tier.id.toHexString(), {
|
|
name: 'Updated'
|
|
});
|
|
|
|
assert(updated.name === 'Updated');
|
|
});
|
|
|
|
it('Can archive a tier', async function () {
|
|
const tier = await api.add({
|
|
name: 'My testing Tier',
|
|
type: 'paid',
|
|
monthlyPrice: 5000,
|
|
yearlyPrice: 50000,
|
|
currency: 'usd'
|
|
});
|
|
|
|
const updated = await api.edit(tier.id.toHexString(), {
|
|
status: 'archived'
|
|
});
|
|
|
|
assert(updated.status === 'archived');
|
|
});
|
|
|
|
it('Can browse tiers', async function () {
|
|
const page = await api.browse();
|
|
|
|
assert(page.data.length === 3);
|
|
assert(page.meta.pagination.total === 3);
|
|
});
|
|
|
|
it('Can read a default tier', async function () {
|
|
const defaultTier = await api.readDefaultTier();
|
|
|
|
assert.equal(defaultTier?.name, 'My testing Tier');
|
|
});
|
|
});
|