mirror of
https://github.com/Cameri/nostream.git
synced 2025-09-17 19:13:35 +02:00
test: remove get default settings
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user