Ghost/ghost/tiers/test/TiersAPI.test.js
Fabien "egg" O'Carroll 0978a808d6 Refactored TiersAPI to use core slug generation
refs https://github.com/TryGhost/Team/issues/2078

This removes the burden from the Tier object, and allows us to reuse
the existing slug generation implementation we have in our bookshelf
models.
2022-10-20 11:54:03 +07:00

76 lines
1.9 KiB
JavaScript

const assert = require('assert');
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',
monthly_price: 5000,
yearly_price: 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',
monthly_price: 5000,
yearly_price: 50000,
currency: 'usd'
});
const updated = await api.edit(tier.id.toHexString(), {
name: 'Updated'
});
assert(updated.name === 'Updated');
});
it('Can browse tiers', async function () {
const page = await api.browse();
assert(page.data.length === 2);
assert(page.meta.pagination.total === 2);
});
});