mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-05-21 03:15:25 +00:00
test: migration from Python to JavaScript
This commit is contained in:
+31
-7
@@ -296,13 +296,37 @@ class WebDAV {
|
||||
}
|
||||
|
||||
syncQuery(resource, token = '', properties) {
|
||||
const formattedProperties = properties.map(p => { return { name: p, namespace: DAVNamespace.DAV } })
|
||||
return syncCollection({
|
||||
url: this.serverUrl + resource,
|
||||
props: formattedProperties,
|
||||
syncLevel: 1,
|
||||
syncToken: token,
|
||||
headers: this.headers
|
||||
const formattedProperties = properties.map((p) => {
|
||||
return { [`${DAVNamespaceShorthandMap[DAVNamespace.DAV]}:${p}`]: '' }
|
||||
});
|
||||
let xmlBody = convert.js2xml(
|
||||
{
|
||||
'sync-collection': {
|
||||
_attributes: getDAVAttribute([DAVNamespace.DAV]),
|
||||
'sync-level': 1,
|
||||
'sync-token': token,
|
||||
prop: formattedProperties
|
||||
}
|
||||
},
|
||||
{
|
||||
compact: true,
|
||||
spaces: 2,
|
||||
elementNameFn: (name) => {
|
||||
// add namespace to all keys without namespace
|
||||
if (!/^.+:.+/.test(name)) {
|
||||
return `${DAVNamespaceShorthandMap[DAVNamespace.DAV]}:${name}`
|
||||
}
|
||||
return name
|
||||
}
|
||||
}
|
||||
)
|
||||
return fetch(this.serverUrl + resource, {
|
||||
headers: {
|
||||
'Content-Type': 'application/xml; charset="utf-8"',
|
||||
...this.headers
|
||||
},
|
||||
method: 'REPORT',
|
||||
body: xmlBody
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -63,6 +63,10 @@ describe('WebDAV', function() {
|
||||
const results = await webdav.principalPropertySearch(resource)
|
||||
expect(results.length).toBe(1)
|
||||
results.forEach(o => {
|
||||
expect(o.status)
|
||||
.withContext(`HTTP status code when a performing a property search`)
|
||||
.toBe(207)
|
||||
expect(o.href).toBe(`/SOGo/dav/${config.username}/`)
|
||||
expect(o.props.displayname).toBe(user.displayname)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import config from '../lib/config'
|
||||
import WebDAV from '../lib/WebDAV'
|
||||
import { DAVNamespace, DAVNamespaceShorthandMap } from 'tsdav'
|
||||
import convert from 'xml-js'
|
||||
|
||||
describe('webdav sync', function() {
|
||||
const webdav = new WebDAV(config.username, config.password)
|
||||
@@ -14,16 +16,17 @@ describe('webdav sync', function() {
|
||||
})
|
||||
|
||||
it("webdav sync", async function() {
|
||||
let results
|
||||
const nsShort = DAVNamespaceShorthandMap[DAVNamespace.DAV].toUpperCase()
|
||||
let response, xml, token
|
||||
|
||||
// missing tests:
|
||||
// invalid tokens: negative, non-numeric, > current timestamp
|
||||
// non-empty collections: token validity, status codes for added,
|
||||
// modified and removed elements
|
||||
|
||||
results = await webdav.makeCalendar(resource)
|
||||
expect(results.length).toBe(1)
|
||||
expect(results[0].status).toBe(201)
|
||||
response = await webdav.makeCalendar(resource)
|
||||
expect(response.length).toBe(1)
|
||||
expect(response[0].status).toBe(201)
|
||||
|
||||
// test queries:
|
||||
// empty collection:
|
||||
@@ -33,16 +36,18 @@ describe('webdav sync', function() {
|
||||
// without a token (query3)
|
||||
// with a token (query4))
|
||||
|
||||
results = await webdav.syncQuery(resource, null, [ 'getetag' ])
|
||||
expect(results.length).toBe(1)
|
||||
expect(results[0].status).toBe(207)
|
||||
// TODO: sync-token is not returned by the tsdav library -- grep raw
|
||||
response = await webdav.syncQuery(resource, null, [ 'getetag' ])
|
||||
xml = await response.text();
|
||||
({ [`${nsShort}:multistatus`]: { [`${nsShort}:sync-token`]: { _text: token } } } = convert.xml2js(xml, {compact: true, nativeType: true}))
|
||||
expect(response.status).toBe(207)
|
||||
expect(token).toBeGreaterThanOrEqual(0)
|
||||
|
||||
// we make sure that any token is accepted when the collection is
|
||||
// empty, but that the returned token differs
|
||||
results = await webdav.syncQuery(resource, '1234', [ 'getetag' ])
|
||||
expect(results.length).toBe(1)
|
||||
expect(results[0].status).toBe(207)
|
||||
// TODO: sync-token is not returned by the tsdav library -- grep raw?
|
||||
response = await webdav.syncQuery(resource, '1234', [ 'getetag' ])
|
||||
xml = await response.text();
|
||||
({ [`${nsShort}:multistatus`]: { [`${nsShort}:sync-token`]: { _text: token } } } = convert.xml2js(xml, {compact: true, nativeType: true}))
|
||||
expect(response.status).toBe(207)
|
||||
expect(token).toBeGreaterThanOrEqual(0)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user