test: migration from Python to JavaScript
This commit is contained in:
parent
96aa444051
commit
05ad7a8d6d
|
@ -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) {
|
propfindEvent(resource) {
|
||||||
return propfind({
|
return propfind({
|
||||||
url: this.serverUrl + resource,
|
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 => {
|
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({
|
return davRequest({
|
||||||
url: this.serverUrl + resource,
|
url: this.serverUrl + resource,
|
||||||
init: {
|
init: {
|
||||||
method: 'PROPPATCH',
|
method: 'PROPPATCH',
|
||||||
headers: this.headers,
|
headers: { ...this.headers, depth: new String(depth) },
|
||||||
namespace: DAVNamespaceShorthandMap[DAVNamespace.DAV],
|
namespace: DAVNamespaceShorthandMap[DAVNamespace.DAV],
|
||||||
body: {
|
body: {
|
||||||
propertyupdate: {
|
propertyupdate: {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import config from '../lib/config'
|
import config from '../lib/config'
|
||||||
import WebDAV from '../lib/WebDAV'
|
import WebDAV from '../lib/WebDAV'
|
||||||
|
|
||||||
describe('default classification', function() {
|
describe('calendar classification', function() {
|
||||||
const webdav = new WebDAV(config.username, config.password)
|
const webdav = new WebDAV(config.username, config.password)
|
||||||
|
|
||||||
const _setClassification = async function(component, classification = '') {
|
const _setClassification = async function(component, classification = '') {
|
||||||
|
|
68
Tests/spec/DAVContactsCategoriesSpec.js
Normal file
68
Tests/spec/DAVContactsCategoriesSpec.js
Normal 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')
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in a new issue