Skip to content

Commit

Permalink
test: migration from Python to JavaScript
Browse files Browse the repository at this point in the history
  • Loading branch information
cgx committed Sep 1, 2021
1 parent b8f0e39 commit 6ae787c
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 15 deletions.
14 changes: 7 additions & 7 deletions Tests/lib/WebDAV.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -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],
Expand All @@ -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],
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions Tests/package.json
Expand Up @@ -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",
Expand Down
20 changes: 15 additions & 5 deletions Tests/spec/DAVCalendarAclSpec.js
Expand Up @@ -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, {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -393,15 +399,19 @@ 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, {
'class': c,
'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)
}
})

Expand Down
56 changes: 56 additions & 0 deletions Tests/spec/HTTPPreferencesSpec.js
@@ -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)
})
})
12 changes: 9 additions & 3 deletions Tests/spec/WebDAVSpec.js
Expand Up @@ -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)
})
})
})
Expand Down
11 changes: 11 additions & 0 deletions Tests/spec/support/jasmine.json
@@ -0,0 +1,11 @@
{
"spec_dir": "spec",
"spec_files": [
"**/*[sS]pec.?(m)js"
],
"helpers": [
"helpers/**/*.?(m)js"
],
"stopSpecOnExpectationFailure": false,
"random": true
}

0 comments on commit 6ae787c

Please sign in to comment.