Skip to content

Commit

Permalink
feat(docs): Add axios mocking for the documentation to allow examples…
Browse files Browse the repository at this point in the history
… of the `NcSettingsSelectGroup`

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux committed May 15, 2023
1 parent 89eae96 commit 972965d
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions styleguide/global.requires.js
Expand Up @@ -5,6 +5,39 @@ import 'regenerator-runtime/runtime'
import Vue from 'vue'
import VTooltip from './../src/directives/Tooltip'

import axios from '@nextcloud/axios'

const USER_GROUPS = [
{ id: 'admin', displayname: 'The administrators' },
{ id: 'foo', displayname: 'Famous foo group' },
{ id: 'bar', displayname: 'Bar group' },
{ id: 'baz', displayname: 'baz' },
{ id: 'users', displayname: 'users' },
]

/**
* Mock some requests for docs
*
* @param {object} error Axios error
*/
function mockRequests(error) {
const { request } = error
let data = null

// Mock requesting groups
const requestGroups = request.responseURL.match(/cloud\/groups\/details\?search=([^&]*)&limit=\d+$/)
if (requestGroups) {
data = { groups: USER_GROUPS.filter(e => !requestGroups[1] || e.displayname.startsWith(requestGroups[1]) || e.id.startsWith(requestGroups[1])) }
}

if (data) {
return Promise.resolve({ data: { ocs: { data } } })
}
return Promise.reject(error)
}

axios.interceptors.response.use((r) => r, e => mockRequests(e))

/**
* From server util.js
*
Expand Down

0 comments on commit 972965d

Please sign in to comment.