test: migration from Python to JavaScript

pull/273/merge
Francis Lachapelle 2021-09-01 11:07:32 -04:00
parent b8f0e39c40
commit 6ae787c4a4
6 changed files with 99 additions and 15 deletions

View File

@ -71,10 +71,10 @@ class WebDAV {
localHeaders.recipients = recipients.join(',')
return fetch(this.serverUrl + resource, {
method: 'POST',
body: vcalendar,
headers: { ...this.headers, ...localHeaders }
})
method: 'POST',
body: vcalendar,
headers: { ...this.headers, ...localHeaders }
})
}
getEvent(resource, filename) {
@ -232,7 +232,7 @@ class WebDAV {
// http://tools.ietf.org/html/rfc3253.html#section-3.8
expendProperty(resource, properties) {
return davRequest({
url: `${this.serverUrl}/${resource}`,
url: this.serverUrl + resource,
init: {
method: 'REPORT',
namespace: DAVNamespaceShorthandMap[DAVNamespace.DAV],
@ -251,7 +251,7 @@ class WebDAV {
syncColletion(resource) {
return davRequest({
url: `${this.serverUrl}/${resource}`,
url: this.serverUrl + resource,
init: {
method: 'REPORT',
namespace: DAVNamespaceShorthandMap[DAVNamespace.DAV],
@ -272,7 +272,7 @@ class WebDAV {
syncQuery(resource, token = '', properties) {
const formattedProperties = properties.map(p => { return { name: p, namespace: DAVNamespace.DAV } })
return syncCollection({
url: `${this.serverUrl}/${resource}`,
url: this.serverUrl + resource,
props: formattedProperties,
syncLevel: 1,
syncToken: token,

View File

@ -10,6 +10,7 @@
"@babel/core": "^7.15.0",
"@babel/preset-env": "^7.15.0",
"babel-cli": "^6.26.0",
"cookie": "^0.4.1",
"cross-fetch": "^3.1.4",
"esm": "^3.2.25",
"ical.js": "^1.4.0",

View File

@ -53,7 +53,9 @@ END:VCALENDAR`
const _checkViewEventRight = function(operation, event, eventClass, right) {
if (right) {
expect(event).toBeTruthy()
expect(event)
.withContext(`Returned event during operation '${operation}'`)
.toBeTruthy()
if (['v', 'r', 'm'].includes(right)) {
const iscClass = classToICSClass[eventClass]
const expectedEvent = utility.formatTemplate(event_template, {
@ -338,7 +340,9 @@ END:VCALENDAR`
const _testEventRight = async function(eventClass, rights) {
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)
event = await _propfindEvent(eventClass)
@ -372,7 +376,9 @@ END:VCALENDAR`
const _testRights = async function(rights) {
const results = await utility.setupCalendarRights(resource, config.subscriber_username, rights)
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 _testCollectionDAVAcl(rights)
await _testEventRight('pu', rights)
@ -393,7 +399,9 @@ END:VCALENDAR`
'filename': eventFilename
})
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
const taskFilename = `${c.toLowerCase()}-task.ics`
const task = utility.formatTemplate(task_template, {
@ -401,7 +409,9 @@ END:VCALENDAR`
'filename': taskFilename
})
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)
}
})

View File

@ -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)
})
})

View File

@ -99,11 +99,17 @@ describe('WebDAV', function() {
expect(results.length).toBe(1)
results.forEach(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 => {
const { response: { href, propstat: { prop: { displayname }} }} = props[p]
expect(href).toBe(outcomes[p].href)
expect(displayname).toBe(outcomes[p].displayname)
expect(href)
.withContext(`Result of expand-property for href`)
.toBe(outcomes[p].href)
expect(displayname)
.withContext(`Result of expand-property for displayname`)
.toBe(outcomes[p].displayname)
})
})
})

View File

@ -0,0 +1,11 @@
{
"spec_dir": "spec",
"spec_files": [
"**/*[sS]pec.?(m)js"
],
"helpers": [
"helpers/**/*.?(m)js"
],
"stopSpecOnExpectationFailure": false,
"random": true
}