test: migration from Python to JavaScript
parent
b8f0e39c40
commit
6ae787c4a4
|
@ -232,7 +232,7 @@ class WebDAV {
|
||||||
// http://tools.ietf.org/html/rfc3253.html#section-3.8
|
// http://tools.ietf.org/html/rfc3253.html#section-3.8
|
||||||
expendProperty(resource, properties) {
|
expendProperty(resource, properties) {
|
||||||
return davRequest({
|
return davRequest({
|
||||||
url: `${this.serverUrl}/${resource}`,
|
url: this.serverUrl + resource,
|
||||||
init: {
|
init: {
|
||||||
method: 'REPORT',
|
method: 'REPORT',
|
||||||
namespace: DAVNamespaceShorthandMap[DAVNamespace.DAV],
|
namespace: DAVNamespaceShorthandMap[DAVNamespace.DAV],
|
||||||
|
@ -251,7 +251,7 @@ class WebDAV {
|
||||||
|
|
||||||
syncColletion(resource) {
|
syncColletion(resource) {
|
||||||
return davRequest({
|
return davRequest({
|
||||||
url: `${this.serverUrl}/${resource}`,
|
url: this.serverUrl + resource,
|
||||||
init: {
|
init: {
|
||||||
method: 'REPORT',
|
method: 'REPORT',
|
||||||
namespace: DAVNamespaceShorthandMap[DAVNamespace.DAV],
|
namespace: DAVNamespaceShorthandMap[DAVNamespace.DAV],
|
||||||
|
@ -272,7 +272,7 @@ class WebDAV {
|
||||||
syncQuery(resource, token = '', properties) {
|
syncQuery(resource, token = '', properties) {
|
||||||
const formattedProperties = properties.map(p => { return { name: p, namespace: DAVNamespace.DAV } })
|
const formattedProperties = properties.map(p => { return { name: p, namespace: DAVNamespace.DAV } })
|
||||||
return syncCollection({
|
return syncCollection({
|
||||||
url: `${this.serverUrl}/${resource}`,
|
url: this.serverUrl + resource,
|
||||||
props: formattedProperties,
|
props: formattedProperties,
|
||||||
syncLevel: 1,
|
syncLevel: 1,
|
||||||
syncToken: token,
|
syncToken: token,
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
"@babel/core": "^7.15.0",
|
"@babel/core": "^7.15.0",
|
||||||
"@babel/preset-env": "^7.15.0",
|
"@babel/preset-env": "^7.15.0",
|
||||||
"babel-cli": "^6.26.0",
|
"babel-cli": "^6.26.0",
|
||||||
|
"cookie": "^0.4.1",
|
||||||
"cross-fetch": "^3.1.4",
|
"cross-fetch": "^3.1.4",
|
||||||
"esm": "^3.2.25",
|
"esm": "^3.2.25",
|
||||||
"ical.js": "^1.4.0",
|
"ical.js": "^1.4.0",
|
||||||
|
|
|
@ -53,7 +53,9 @@ END:VCALENDAR`
|
||||||
|
|
||||||
const _checkViewEventRight = function(operation, event, eventClass, right) {
|
const _checkViewEventRight = function(operation, event, eventClass, right) {
|
||||||
if (right) {
|
if (right) {
|
||||||
expect(event).toBeTruthy()
|
expect(event)
|
||||||
|
.withContext(`Returned event during operation '${operation}'`)
|
||||||
|
.toBeTruthy()
|
||||||
if (['v', 'r', 'm'].includes(right)) {
|
if (['v', 'r', 'm'].includes(right)) {
|
||||||
const iscClass = classToICSClass[eventClass]
|
const iscClass = classToICSClass[eventClass]
|
||||||
const expectedEvent = utility.formatTemplate(event_template, {
|
const expectedEvent = utility.formatTemplate(event_template, {
|
||||||
|
@ -338,7 +340,9 @@ END:VCALENDAR`
|
||||||
const _testEventRight = async function(eventClass, rights) {
|
const _testEventRight = async function(eventClass, rights) {
|
||||||
const right = Object.keys(rights).includes(eventClass) ? rights[eventClass] : undefined
|
const right = Object.keys(rights).includes(eventClass) ? rights[eventClass] : undefined
|
||||||
|
|
||||||
let event = await _getEvent(eventClass)
|
let event
|
||||||
|
|
||||||
|
event = await _getEvent(eventClass)
|
||||||
_checkViewEventRight('GET', event, eventClass, right)
|
_checkViewEventRight('GET', event, eventClass, right)
|
||||||
|
|
||||||
event = await _propfindEvent(eventClass)
|
event = await _propfindEvent(eventClass)
|
||||||
|
@ -372,7 +376,9 @@ END:VCALENDAR`
|
||||||
const _testRights = async function(rights) {
|
const _testRights = async function(rights) {
|
||||||
const results = await utility.setupCalendarRights(resource, config.subscriber_username, rights)
|
const results = await utility.setupCalendarRights(resource, config.subscriber_username, rights)
|
||||||
expect(results.length).toBe(1)
|
expect(results.length).toBe(1)
|
||||||
expect(results[0].status).toBe(204)
|
expect(results[0].status)
|
||||||
|
.withContext(`Setup rights (${JSON.stringify(rights)}) on ${resource}`)
|
||||||
|
.toBe(204)
|
||||||
await _testCreate(rights)
|
await _testCreate(rights)
|
||||||
await _testCollectionDAVAcl(rights)
|
await _testCollectionDAVAcl(rights)
|
||||||
await _testEventRight('pu', rights)
|
await _testEventRight('pu', rights)
|
||||||
|
@ -393,7 +399,9 @@ END:VCALENDAR`
|
||||||
'filename': eventFilename
|
'filename': eventFilename
|
||||||
})
|
})
|
||||||
let response = await webdav.createCalendarObject(resource, eventFilename, event)
|
let response = await webdav.createCalendarObject(resource, eventFilename, event)
|
||||||
expect(response.status).toBe(201)
|
expect(response.status)
|
||||||
|
.withContext(`HTTP status when creating event with ${c} class`)
|
||||||
|
.toBe(201)
|
||||||
// Create task for each class
|
// Create task for each class
|
||||||
const taskFilename = `${c.toLowerCase()}-task.ics`
|
const taskFilename = `${c.toLowerCase()}-task.ics`
|
||||||
const task = utility.formatTemplate(task_template, {
|
const task = utility.formatTemplate(task_template, {
|
||||||
|
@ -401,7 +409,9 @@ END:VCALENDAR`
|
||||||
'filename': taskFilename
|
'filename': taskFilename
|
||||||
})
|
})
|
||||||
response = await webdav.createCalendarObject(resource, taskFilename, task)
|
response = await webdav.createCalendarObject(resource, taskFilename, task)
|
||||||
expect(response.status).toBe(201)
|
expect(response.status)
|
||||||
|
.withContext(`HTTP status when creating task with ${c} class`)
|
||||||
|
.toBe(201)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
import config from '../lib/config'
|
||||||
|
import Preferences from '../lib/Preferences'
|
||||||
|
|
||||||
|
const prefs = new Preferences(config.username, config.password)
|
||||||
|
|
||||||
|
beforeAll(async function() {
|
||||||
|
// because if not set in vacation will not be found later
|
||||||
|
// we must make sure they are there at the start
|
||||||
|
await prefs.setOrCreate('autoReplyText', '', ['defaults', 'Vacation'])
|
||||||
|
await prefs.setOrCreate('PreventInvitations', 0, ['settings', 'Calendar'])
|
||||||
|
await prefs.setOrCreate('PreventInvitationsWhitelist', {}, ['settings', 'Calendar'])
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('preferences', function() {
|
||||||
|
|
||||||
|
const _setTextPref = async function(prefText) {
|
||||||
|
await prefs.set('autoReplyText', prefText)
|
||||||
|
const prefData = await prefs.get('Vacation')
|
||||||
|
|
||||||
|
expect(prefData.autoReplyText)
|
||||||
|
.withContext(`Set a text preference to a known value`)
|
||||||
|
.toEqual(prefText)
|
||||||
|
}
|
||||||
|
|
||||||
|
// preferencesTest
|
||||||
|
|
||||||
|
it('Set/get a text preference - normal characters', async function() {
|
||||||
|
await _setTextPref('defaultText')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Set/get a text preference - weird characters - used to crash on 1.3.12', async function() {
|
||||||
|
const prefText = `weird data \ ' \"; ^`
|
||||||
|
await _setTextPref(prefText)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Set/get the PreventInvitation pref', async function() {
|
||||||
|
await prefs.set('PreventInvitations', 0)
|
||||||
|
const notset = await prefs.get('Calendar', false)
|
||||||
|
expect(notset.PreventInvitations)
|
||||||
|
.withContext(`Set/get Settings/Calendar/PreventInvitations (0)`)
|
||||||
|
.toEqual(0)
|
||||||
|
await prefs.set('PreventInvitations', 1)
|
||||||
|
const isset = await prefs.get('Calendar', false)
|
||||||
|
expect(isset.PreventInvitations)
|
||||||
|
.withContext(`Set/get Settings/Calendar/PreventInvitations (1)`)
|
||||||
|
.toEqual(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Set/get the PreventInvitations Whitelist', async function() {
|
||||||
|
await prefs.set('PreventInvitationsWhitelist', config.white_listed_attendee)
|
||||||
|
const whitelist = await prefs.get('Calendar', false)
|
||||||
|
expect(whitelist.PreventInvitationsWhitelist)
|
||||||
|
.withContext(`Set/get Settings/Calendar/PreventInvitationsWhitelist`)
|
||||||
|
.toEqual(config.white_listed_attendee)
|
||||||
|
})
|
||||||
|
})
|
|
@ -99,11 +99,17 @@ describe('WebDAV', function() {
|
||||||
expect(results.length).toBe(1)
|
expect(results.length).toBe(1)
|
||||||
results.forEach(o => {
|
results.forEach(o => {
|
||||||
const { props = {} } = o
|
const { props = {} } = o
|
||||||
expect(o.status).toBe(207)
|
expect(o.status)
|
||||||
|
.withContext(`HTTP status code when expanding properties`)
|
||||||
|
.toBe(207)
|
||||||
Object.keys(outcomes).forEach(p => {
|
Object.keys(outcomes).forEach(p => {
|
||||||
const { response: { href, propstat: { prop: { displayname }} }} = props[p]
|
const { response: { href, propstat: { prop: { displayname }} }} = props[p]
|
||||||
expect(href).toBe(outcomes[p].href)
|
expect(href)
|
||||||
expect(displayname).toBe(outcomes[p].displayname)
|
.withContext(`Result of expand-property for href`)
|
||||||
|
.toBe(outcomes[p].href)
|
||||||
|
expect(displayname)
|
||||||
|
.withContext(`Result of expand-property for displayname`)
|
||||||
|
.toBe(outcomes[p].displayname)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
"spec_dir": "spec",
|
||||||
|
"spec_files": [
|
||||||
|
"**/*[sS]pec.?(m)js"
|
||||||
|
],
|
||||||
|
"helpers": [
|
||||||
|
"helpers/**/*.?(m)js"
|
||||||
|
],
|
||||||
|
"stopSpecOnExpectationFailure": false,
|
||||||
|
"random": true
|
||||||
|
}
|
Loading…
Reference in New Issue