test: migration from Python to JavaScript

pull/301/head
Francis Lachapelle 2021-08-20 17:36:05 -04:00
parent 96aa444051
commit 05ad7a8d6d
3 changed files with 101 additions and 4 deletions

View File

@ -83,6 +83,29 @@ class WebDAV {
})
}
propfindWebdav(resource, properties, depth = 0) {
const formattedProperties = properties.map(p => {
return { [`i:${p}`]: '' }
})
return davRequest({
url: this.serverUrl + resource,
init: {
method: 'PROPFIND',
headers: { ...this.headers, depth: new String(depth) },
namespace: DAVNamespaceShorthandMap[DAVNamespace.DAV],
body: {
propfind: {
_attributes: {
...getDAVAttribute([DAVNamespace.DAV]),
'xmlns:i': 'urn:inverse:params:xml:ns:inverse-dav'
},
prop: formattedProperties
}
}
}
})
}
propfindEvent(resource) {
return propfind({
url: this.serverUrl + resource,
@ -264,15 +287,21 @@ class WebDAV {
})
}
proppatchWebdav(resource, properties) {
proppatchWebdav(resource, properties, depth = 0) {
const formattedProperties = Object.keys(properties).map(p => {
return { [`i:${p}`]: properties[p] }
if (typeof properties[p] == 'object') {
return { [`i:${p}`]: properties[p].map(pp => {
const [ key ] = Object.keys(pp)
return { [`i:${key}`]: pp[key] || '' }
})}
}
return { [`i:${p}`]: properties[p] || '' }
})
return davRequest({
url: this.serverUrl + resource,
init: {
method: 'PROPPATCH',
headers: this.headers,
headers: { ...this.headers, depth: new String(depth) },
namespace: DAVNamespaceShorthandMap[DAVNamespace.DAV],
body: {
propertyupdate: {

View File

@ -1,7 +1,7 @@
import config from '../lib/config'
import WebDAV from '../lib/WebDAV'
describe('default classification', function() {
describe('calendar classification', function() {
const webdav = new WebDAV(config.username, config.password)
const _setClassification = async function(component, classification = '') {

View File

@ -0,0 +1,68 @@
import config from '../lib/config'
import WebDAV from '../lib/WebDAV'
describe('contacts categories', function() {
const webdav = new WebDAV(config.username, config.password)
const _setCategories = async function(categories = []) {
const resource = `/SOGo/dav/${config.username}/Contacts/`
const elements = categories.map(c => {
return { 'category': c }
})
const properties = { 'contacts-categories': elements.length ? elements : '' }
const results = await webdav.proppatchWebdav(resource, properties)
expect(results.length)
.withContext(`Set contacts categories to ${categories.join(', ')}`)
.toBe(1)
return results[0].status
}
const _getCategories = async function() {
const resource = `/SOGo/dav/${config.username}/Contacts/`
const properties = ['contacts-categories']
const results = await webdav.propfindWebdav(resource, properties)
expect(results.length)
.toBe(1)
const { props: { contactsCategories: { category } = {} } = {} } = results[0]
return category
}
// HTTPContactCategoriesTest
it('setting contacts categories', async function() {
let status, results
status = await _setCategories()
expect(status)
.withContext('Removing contacts categories')
.toBe(207)
results = await _getCategories()
expect(results)
.toBeUndefined()
status = await _setCategories(['Coucou'])
expect(status)
.withContext('Setting one contacts category')
.toBe(207)
results = await _getCategories()
expect(results)
.toBe('Coucou')
status = await _setCategories(['Toto', 'Cuicui'])
expect(status)
.withContext('Setting two contacts category')
.toBe(207)
results = await _getCategories()
expect(results.length)
.toBe(2)
expect(results)
.toContain('Toto')
expect(results)
.toContain('Cuicui')
})
})