Skip to content
Snippets Groups Projects
Commit 8eef51ad authored by Angelina Filippova's avatar Angelina Filippova
Browse files

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

parent a58143e3
No related branches found
No related tags found
No related merge requests found
......@@ -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
}
......
......@@ -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)
}
}
}
......
......@@ -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()
})
})
\ No newline at end of file
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
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment