Add tests for fetching media proxy settings, evicting single and multiple urls

This commit is contained in:
Angelina Filippova 2020-09-08 21:02:45 +03:00
parent e1b9ccdef1
commit 6069a95768
4 changed files with 80 additions and 28 deletions

View file

@ -6,6 +6,16 @@ const configsWithTagPolicy = {
{ tuple: [':policies', ['Pleroma.Web.ActivityPub.MRF.ObjectAgePolicy', 'Pleroma.Web.ActivityPub.MRF.TagPolicy']] },
{ tuple: [':transparency', true] },
{ tuple: [':transparency_exclusions', []] }
] },
{
group: ':pleroma',
key: ':media_proxy',
value: [
{ tuple: [':enabled', true] },
{ tuple: [':invalidation', [
{ tuple: [':provider', 'Pleroma.Web.MediaProxy.Invalidation.Script'] },
{ tuple: [':enabled', true] }
]] }
] }],
need_reboot: false
}

View file

@ -146,7 +146,7 @@ export default {
})
},
evictURL() {
const urls = this.urls.split(',').map(url => url.trim()).filter(el => el.length > 0)
const urls = this.splitUrls(this.urls)
this.$store.dispatch('PurgeUrls', { urls, ban: this.ban })
this.urls = ''
},
@ -163,6 +163,9 @@ export default {
},
removeUrl(url) {
this.$store.dispatch('RemoveBannedUrls', [url])
},
splitUrls(urls) {
return urls.split(',').map(url => url.trim()).filter(el => el.length > 0)
}
}
}

View file

@ -3,8 +3,11 @@ import { mount, createLocalVue, config } from '@vue/test-utils'
import flushPromises from 'flush-promises'
import Element from 'element-ui'
import MediaProxyCache from '@/views/mediaProxyCache/index'
import storeConfig from './store.conf'
import { cloneDeep } from 'lodash'
import app from '@/store/modules/app'
import mediaProxyCache from '@/store/modules/mediaProxyCache'
import settings from '@/store/modules/settings'
import user from '@/store/modules/user'
import getters from '@/store/getters'
config.mocks["$t"] = () => {}
@ -17,11 +20,21 @@ jest.mock('@/api/nodeInfo')
jest.mock('@/api/mediaProxyCache')
jest.mock('@/api/settings')
describe('', () => {
describe('MediaProxy Cache Invalidation', () => {
let store
let actions
beforeEach(() => {
store = new Vuex.Store(cloneDeep(storeConfig))
actions = { ...mediaProxyCache.actions, PurgeUrls: jest.fn() }
store = new Vuex.Store({
modules: {
app,
mediaProxyCache: { ...mediaProxyCache, actions },
user,
settings,
},
getters
})
})
it('fetches initial list of urls', async (done) => {
@ -32,9 +45,56 @@ describe('', () => {
})
await flushPromises()
console.log(store.state)
console.log(wrapper.html())
expect(wrapper.vm.urlsCount).toEqual(2)
expect(wrapper.vm.mediaProxyEnabled).toBeTruthy()
done()
})
it('evicts single url', async (done) => {
const wrapper = mount(MediaProxyCache, {
store,
localVue,
sync: false
})
await flushPromises()
const textarea = wrapper.find('.url-input textarea')
const button = wrapper.find('.url-input-container button')
const value = 'http://example.com/media/asdf89.jpg'
const expectedUrls = ['http://example.com/media/asdf89.jpg']
textarea.element.value = value
textarea.trigger('input')
button.trigger('click')
await flushPromises()
expect(actions.PurgeUrls).toHaveBeenCalled()
expect(wrapper.vm.urls.length).toEqual(0)
expect(wrapper.vm.splitUrls(value)).toEqual(expectedUrls)
done()
})
it('evicts multiple urls', async (done) => {
const wrapper = mount(MediaProxyCache, {
store,
localVue,
sync: false
})
await flushPromises()
const textarea = wrapper.find('.url-input textarea')
const button = wrapper.find('.url-input-container button')
const value = ' http://example.com/media/asdf89.jpg,http://example.com/media/oi678lk.jpg, http://example.com/media/kdjhf87.jpg , http://example.com/media/98234sd.jpg'
const expectedUrls = ['http://example.com/media/asdf89.jpg', 'http://example.com/media/oi678lk.jpg', 'http://example.com/media/kdjhf87.jpg', 'http://example.com/media/98234sd.jpg']
textarea.element.value = value
textarea.trigger('input')
button.trigger('click')
await flushPromises()
expect(actions.PurgeUrls).toHaveBeenCalled()
expect(wrapper.vm.urls.length).toEqual(0)
expect(wrapper.vm.splitUrls(value)).toEqual(expectedUrls)
done()
})
})

View file

@ -1,21 +0,0 @@
import app from '@/store/modules/app'
import mediaProxyCache from '@/store/modules/mediaProxyCache'
import user from '@/store/modules/user'
import users from '@/store/modules/users'
import reports from '@/store/modules/reports'
import settings from '@/store/modules/settings'
import status from '@/store/modules/status'
import getters from '@/store/getters'
export default {
modules: {
app,
mediaProxyCache,
user,
users,
reports,
settings,
status
},
getters
}