todos-contra-el-fuego-web/test/server/siteSettings.test.js
vjrj 6b6f02d92d quality: web debt batch (tests runner, FireContainer, rate-limit, maps, i18n)
Independent-of-prod quality debt from PENDIENTE.md §2:

- test: migrate broken Jest -> meteortesting:mocha. Tests rewritten to chai +
  Meteor 3 async APIs, moved to test/server/ (server-only). test/server/
  00-setup.test.js re-runs the collection2/accounts init that `meteor test`
  skips (no server/main.js). New comments method + mediaAnalyzers coverage.
  Dropped rest.test.js (removed meteor/http; covered by smoke/). 36 passing.
- fix: scope FireContainer read by the URL _id on the archive route instead of
  a selector-less FiresCollection.findOne() (imports/ui/pages/Fires/Fires.js).
- feat: rate-limit abusable publications via rateLimitSubscriptions (fireFrom*
  and comments.forReference 5/1000ms; geo subs 10/1000ms).
- perf: append loading=async to the Google Maps loader URL (Gkeys.js).
- deps: meteor-accounts-t9n 2.0 -> 2.6 (no gl build -> keep gl->es fallback,
  documented); add 3 missing gl/common.json keys (0 missing now).
- deps: drop jest/babel/enzyme, add chai.
2026-07-21 22:59:06 +02:00

58 lines
1.7 KiB
JavaScript

/* eslint-env mocha */
/* eslint-disable func-names, prefer-arrow-callback */
/* eslint-disable import/no-absolute-path */
import { expect } from 'chai';
import SiteSettings from '/imports/api/SiteSettings/SiteSettings';
import SiteSettingsTypes from '/imports/api/SiteSettings/SiteSettingsTypes';
const setting = {
name: 'site-test',
value: 'Some value',
description: 'Some description',
isPublic: true,
type: 'string'
};
describe('site settings store', () => {
before(async () => {
await SiteSettings.createIndexAsync({ name: 1 }, { unique: true });
await SiteSettings.removeAsync({ name: setting.name });
});
it('should get settingstypes', () => {
expect(SiteSettingsTypes.string.value.type).to.equal(String);
});
it('should insert settings', async () => {
const id = await SiteSettings.insertAsync(setting);
SiteSettings.getSchema(setting.type).validate(setting);
const inserted = await SiteSettings.findOneAsync(id);
delete inserted._id;
expect(inserted).to.deep.equal(setting);
await SiteSettings.removeAsync(id);
expect(await SiteSettings.find({ _id: id }).countAsync()).to.equal(0);
});
it('should not be inserted twice', async () => {
const id = await SiteSettings.insertAsync(setting);
// The unique index on `name` must reject the duplicate.
let threw = false;
try {
await SiteSettings.insertAsync(setting);
} catch (e) {
threw = true;
}
expect(threw).to.equal(true);
expect(await SiteSettings.find(id).countAsync()).to.equal(1);
await SiteSettings.removeAsync(id);
});
it('should fail validation', () => {
expect(() => {
SiteSettings.getSchema('boolean').validate(setting);
}).to.throw('Value must be of type Boolean');
});
});