mirror of
https://github.com/Cameri/nostream.git
synced 2025-03-17 21:31:48 +01:00
test: remove get default settings
This commit is contained in:
parent
4f0e6a8b5d
commit
cce2df0c2a
@ -4,9 +4,7 @@ import { join } from 'path'
|
||||
import { mergeDeepRight } from 'ramda'
|
||||
|
||||
import { createLogger } from '../factories/logger-factory'
|
||||
import { EventKinds } from '../constants/base'
|
||||
import { ISettings } from '../@types/settings'
|
||||
import packageJson from '../../package.json'
|
||||
import settingsSampleJson from '../../settings.sample.json'
|
||||
|
||||
const debug = createLogger('settings')
|
||||
@ -21,131 +19,6 @@ export class SettingsStatic {
|
||||
)
|
||||
}
|
||||
|
||||
public static getDefaultSettings(): ISettings {
|
||||
return {
|
||||
info: {
|
||||
relay_url: 'wss://nostr-ts-relay.your-domain.com',
|
||||
name: `${packageJson.name}.your-domain.com`,
|
||||
description: packageJson.description,
|
||||
pubkey: 'replace-with-your-pubkey',
|
||||
contact: 'operator@your-domain.com',
|
||||
},
|
||||
workers: {
|
||||
count: 0,
|
||||
},
|
||||
limits: {
|
||||
event: {
|
||||
eventId: {
|
||||
minLeadingZeroBits: 0,
|
||||
},
|
||||
kind: {
|
||||
whitelist: [],
|
||||
blacklist: [],
|
||||
},
|
||||
pubkey: {
|
||||
minLeadingZeroBits: 0,
|
||||
whitelist: [],
|
||||
blacklist: [],
|
||||
},
|
||||
createdAt: {
|
||||
maxPositiveDelta: 900,
|
||||
maxNegativeDelta: 0, // disabled
|
||||
},
|
||||
content: {
|
||||
maxLength: 1048576,
|
||||
},
|
||||
rateLimits: [
|
||||
{
|
||||
kinds: [
|
||||
EventKinds.SET_METADATA,
|
||||
EventKinds.CONTACT_LIST,
|
||||
EventKinds.CHANNEL_CREATION,
|
||||
EventKinds.CHANNEL_METADATA,
|
||||
],
|
||||
period: 60000,
|
||||
rate: 6,
|
||||
},
|
||||
{
|
||||
kinds: [
|
||||
EventKinds.TEXT_NOTE,
|
||||
EventKinds.RECOMMEND_SERVER,
|
||||
EventKinds.ENCRYPTED_DIRECT_MESSAGE,
|
||||
EventKinds.CHANNEL_MESSAGE,
|
||||
],
|
||||
period: 60000,
|
||||
rate: 12,
|
||||
},
|
||||
{
|
||||
kinds: [
|
||||
EventKinds.TEXT_NOTE,
|
||||
EventKinds.RECOMMEND_SERVER,
|
||||
EventKinds.ENCRYPTED_DIRECT_MESSAGE,
|
||||
EventKinds.CHANNEL_MESSAGE,
|
||||
],
|
||||
period: 3600000,
|
||||
rate: 360,
|
||||
},
|
||||
{
|
||||
kinds: [
|
||||
[EventKinds.DELETE, EventKinds.REACTION],
|
||||
[EventKinds.CHANNEL_HIDE_MESSAGE, EventKinds.CHANNEL_RESERVED_LAST],
|
||||
],
|
||||
period: 60000,
|
||||
rate: 30,
|
||||
},
|
||||
{
|
||||
kinds: [
|
||||
[EventKinds.REPLACEABLE_FIRST, EventKinds.REPLACEABLE_LAST],
|
||||
[EventKinds.PARAMETERIZED_REPLACEABLE_FIRST, EventKinds.PARAMETERIZED_REPLACEABLE_LAST],
|
||||
],
|
||||
period: 60000,
|
||||
rate: 24,
|
||||
},
|
||||
{
|
||||
kinds: [[EventKinds.EPHEMERAL_FIRST, EventKinds.EPHEMERAL_LAST]],
|
||||
period: 60000,
|
||||
rate: 60,
|
||||
},
|
||||
{
|
||||
period: 3600000,
|
||||
rate: 720,
|
||||
},
|
||||
{
|
||||
period: 86400000,
|
||||
rate: 2880,
|
||||
},
|
||||
],
|
||||
},
|
||||
client: {
|
||||
subscription: {
|
||||
maxSubscriptions: 10,
|
||||
maxFilters: 10,
|
||||
},
|
||||
},
|
||||
message: {
|
||||
rateLimits: [
|
||||
{
|
||||
period: 60000,
|
||||
rate: 120,
|
||||
},
|
||||
{
|
||||
period: 3600000,
|
||||
rate: 3600,
|
||||
},
|
||||
{
|
||||
period: 86400000,
|
||||
rate: 86400,
|
||||
},
|
||||
],
|
||||
ipWhitelist: [
|
||||
'::1', // local host
|
||||
'::ffff:10.10.10.1', // host running docker
|
||||
],
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
public static loadSettings(path: string) {
|
||||
debug('loading settings from %s', path)
|
||||
return JSON.parse(
|
||||
|
@ -38,94 +38,6 @@ describe('SettingsStatic', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('.getDefaultSettings', () => {
|
||||
it('returns object with info', () => {
|
||||
expect(SettingsStatic.getDefaultSettings())
|
||||
.to.have.property('info')
|
||||
.and.to.deep.equal({
|
||||
relay_url: 'wss://nostr-ts-relay.your-domain.com',
|
||||
name: 'nostr-ts-relay.your-domain.com',
|
||||
description: 'A nostr relay written in Typescript.',
|
||||
pubkey: 'replace-with-your-pubkey',
|
||||
contact: 'operator@your-domain.com',
|
||||
})
|
||||
})
|
||||
|
||||
it('returns object with default limits', () => {
|
||||
expect(SettingsStatic.getDefaultSettings())
|
||||
.to.have.property('limits')
|
||||
.and.to.deep.equal({
|
||||
event: {
|
||||
eventId: {
|
||||
minLeadingZeroBits: 0,
|
||||
},
|
||||
kind: {
|
||||
whitelist: [],
|
||||
blacklist: [],
|
||||
},
|
||||
pubkey: {
|
||||
minLeadingZeroBits: 0,
|
||||
whitelist: [],
|
||||
blacklist: [],
|
||||
},
|
||||
createdAt: {
|
||||
maxPositiveDelta: 900, // +15 min
|
||||
maxNegativeDelta: 0, // disabled
|
||||
},
|
||||
content: {
|
||||
maxLength: 1048576,
|
||||
},
|
||||
'rateLimits': [
|
||||
{
|
||||
'kinds': [[0, 5], 7, [40, 49], [10000, 19999], [30000, 39999]],
|
||||
'period': 60000,
|
||||
'rate': 60,
|
||||
},
|
||||
{
|
||||
'kinds': [[20000, 29999]],
|
||||
'period': 60000,
|
||||
'rate': 600,
|
||||
},
|
||||
{
|
||||
'period': 3600000,
|
||||
'rate': 3600,
|
||||
},
|
||||
{
|
||||
'period': 86400000,
|
||||
'rate': 86400,
|
||||
},
|
||||
],
|
||||
},
|
||||
client: {
|
||||
subscription: {
|
||||
maxSubscriptions: 10,
|
||||
maxFilters: 10,
|
||||
},
|
||||
},
|
||||
message: {
|
||||
'rateLimits': [
|
||||
{
|
||||
'period': 60000,
|
||||
'rate': 600,
|
||||
},
|
||||
{
|
||||
'period': 3600000,
|
||||
'rate': 3600,
|
||||
},
|
||||
{
|
||||
'period': 86400000,
|
||||
'rate': 86400,
|
||||
},
|
||||
],
|
||||
ipWhitelist: [
|
||||
'::1',
|
||||
'::ffff:10.10.10.1',
|
||||
],
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('.loadSettings', () => {
|
||||
let readFileSyncStub: Sinon.SinonStub
|
||||
|
||||
@ -152,7 +64,6 @@ describe('SettingsStatic', () => {
|
||||
describe('.createSettings', () => {
|
||||
let existsSyncStub: Sinon.SinonStub
|
||||
let getSettingsFilePathStub: Sinon.SinonStub
|
||||
let getDefaultSettingsStub: Sinon.SinonStub
|
||||
let saveSettingsStub: Sinon.SinonStub
|
||||
let loadSettingsStub: Sinon.SinonStub
|
||||
|
||||
@ -165,7 +76,6 @@ describe('SettingsStatic', () => {
|
||||
|
||||
existsSyncStub = sandbox.stub(fs, 'existsSync')
|
||||
getSettingsFilePathStub = sandbox.stub(SettingsStatic, 'getSettingsFilePath')
|
||||
getDefaultSettingsStub = sandbox.stub(SettingsStatic, 'getDefaultSettings')
|
||||
saveSettingsStub = sandbox.stub(SettingsStatic, 'saveSettings')
|
||||
loadSettingsStub = sandbox.stub(SettingsStatic, 'loadSettings')
|
||||
})
|
||||
@ -175,70 +85,60 @@ describe('SettingsStatic', () => {
|
||||
})
|
||||
|
||||
it('creates settings from default if settings file is missing', () => {
|
||||
getDefaultSettingsStub.returns({})
|
||||
getSettingsFilePathStub.returns('/some/path/settings.json')
|
||||
existsSyncStub.returns(false)
|
||||
|
||||
expect(SettingsStatic.createSettings()).to.deep.equal({})
|
||||
expect(SettingsStatic.createSettings()).to.be.an('object')
|
||||
|
||||
expect(existsSyncStub).to.have.been.calledOnceWithExactly('/some/path/settings.json')
|
||||
expect(getSettingsFilePathStub).to.have.been.calledOnce
|
||||
expect(getDefaultSettingsStub).to.have.been.calledOnce
|
||||
expect(saveSettingsStub).to.have.been.calledOnceWithExactly(
|
||||
'/some/path/settings.json',
|
||||
{},
|
||||
Sinon.match.object,
|
||||
)
|
||||
expect(loadSettingsStub).not.to.have.been.called
|
||||
})
|
||||
|
||||
it('returns default settings if saving settings file throws', () => {
|
||||
const error = new Error('mistakes were made')
|
||||
const defaults = Symbol()
|
||||
getSettingsFilePathStub.returns('/some/path/settings.json')
|
||||
getDefaultSettingsStub.returns(defaults)
|
||||
saveSettingsStub.throws(error)
|
||||
existsSyncStub.returns(false)
|
||||
|
||||
expect(SettingsStatic.createSettings()).to.equal(defaults)
|
||||
expect(SettingsStatic.createSettings()).to.be.an('object')
|
||||
|
||||
expect(existsSyncStub).to.have.been.calledOnceWithExactly('/some/path/settings.json')
|
||||
expect(getSettingsFilePathStub).to.have.been.calledOnce
|
||||
expect(getDefaultSettingsStub).to.have.been.calledOnce
|
||||
expect(saveSettingsStub).to.have.been.calledOnceWithExactly(
|
||||
'/some/path/settings.json',
|
||||
defaults,
|
||||
Sinon.match.object,
|
||||
)
|
||||
expect(loadSettingsStub).not.to.have.been.called
|
||||
})
|
||||
|
||||
it('loads settings from file if settings file is exists', () => {
|
||||
getDefaultSettingsStub.returns({})
|
||||
loadSettingsStub.returns({})
|
||||
getSettingsFilePathStub.returns('/some/path/settings.json')
|
||||
existsSyncStub.returns(true)
|
||||
|
||||
expect(SettingsStatic.createSettings()).to.deep.equal({})
|
||||
expect(SettingsStatic.createSettings()).to.be.an('object')
|
||||
|
||||
expect(existsSyncStub).to.have.been.calledOnceWithExactly('/some/path/settings.json')
|
||||
expect(getSettingsFilePathStub).to.have.been.calledOnce
|
||||
expect(getDefaultSettingsStub).to.have.been.calledOnce
|
||||
expect(saveSettingsStub).not.to.have.been.called
|
||||
expect(loadSettingsStub).to.have.been.calledOnceWithExactly('/some/path/settings.json')
|
||||
})
|
||||
|
||||
it('returns defaults if loading settings file throws', () => {
|
||||
const defaults = Symbol()
|
||||
const error = new Error('mistakes were made')
|
||||
getDefaultSettingsStub.returns(defaults)
|
||||
loadSettingsStub.throws(error)
|
||||
getSettingsFilePathStub.returns('/some/path/settings.json')
|
||||
existsSyncStub.returns(true)
|
||||
|
||||
expect(SettingsStatic.createSettings()).to.equal(defaults)
|
||||
expect(SettingsStatic.createSettings()).to.be.an('object')
|
||||
|
||||
expect(existsSyncStub).to.have.been.calledOnceWithExactly('/some/path/settings.json')
|
||||
expect(getSettingsFilePathStub).to.have.been.calledOnce
|
||||
expect(getDefaultSettingsStub).to.have.been.calledOnce
|
||||
expect(saveSettingsStub).not.to.have.been.called
|
||||
expect(loadSettingsStub).to.have.been.calledOnceWithExactly('/some/path/settings.json')
|
||||
})
|
||||
@ -250,7 +150,6 @@ describe('SettingsStatic', () => {
|
||||
expect(SettingsStatic.createSettings()).to.equal(cachedSettings)
|
||||
|
||||
expect(getSettingsFilePathStub).not.to.have.been.calledOnce
|
||||
expect(getDefaultSettingsStub).not.to.have.been.calledOnce
|
||||
expect(existsSyncStub).not.to.have.been.called
|
||||
expect(saveSettingsStub).not.to.have.been.called
|
||||
expect(loadSettingsStub).not.to.have.been.called
|
||||
|
Loading…
x
Reference in New Issue
Block a user