<commit_before>// TODO: Unskip the tests after the issue is fixed
// https://github.com/owncloud/owncloud-sdk/issues/705
import { MatchersV3, XmlBuilder } from '@pact-foundation/pact/v3'

describe('Main: Currently testing file versions management,', function () {
  const config = require('./config/config.json')

  const {
    validAdminAuthHeaders,
    accessControlAllowHeaders,
    accessControlAllowMethods,
    applicationXmlResponseHeaders,
    getContentsOfFileInteraction,
    getCurrentUserInformationInteraction,
    getCapabilitiesInteraction,
    createOwncloud,
    createProvider
  } = require('./pactHelper.js')

  // TESTING CONFIGS
  const versionedFile = config.testFile
  const fileInfo = {
    id: 12345678,
    versions: [
      {
        versionId: 98765432,
        content: config.testContent
      },
      {
        versionId: 87654321,
        content: '*'
      }
    ]
  }
  const propfindFileVersionsRequestData = {
    method: 'PROPFIND',
    path: MatchersV3.regex({
      matcher: `.*\\/remote\\.php\\/dav\\/meta\\/${fileInfo.id}\\/v$`,
      generate: `/remote.php/dav/meta/${fileInfo.id}/v`
    }),
    headers: validAdminAuthHeaders,
    body: new XmlBuilder('1.0', '', 'd:propfind').build(dPropfind => {
      dPropfind.setAttributes({ 'xmlns:d': 'DAV:', 'xmlns:oc': 'http://owncloud.org/ns' })
      dPropfind.appendElement('d:prop', '', '')
    })
  }

  const header = {
    ...applicationXmlResponseHeaders,
    'Access-Control-Allow-Headers': accessControlAllowHeaders,
    'Access-Control-Allow-Methods': accessControlAllowMethods
  }

  const propfindFileVersionsResponse = (node, version, contentLength) => {
    return node.appendElement('d:response', '', dResponse => {
      dResponse.appendElement('d:href', '', `/remote.php/dav/meta/${fileInfo.id}/v/${fileInfo.versions[version].versionId}`)
        .appendElement('d:propstat', '', dPropstat => {
          dPropstat.appendElement('d:prop', '', dProp => {
            dProp
              .appendElement('d:getlastmodified', '', 'Thu, 08 Oct 2020 02:28:50 GMT')
              .appendElement('d:getcontentlength', '', contentLength)
              .appendElement('d:resourcetype', '', '')
              .appendElement('d:getetag', '', '&quot;bc7012325dcc9899be7da7cabfdddb00&quot;')
              .appendElement('d:getcontenttype', '', 'text/plain')
          })
            .appendElement('d:status', '', 'HTTP/1.1 200 OK')
        }).appendElement('d:propstat', '', dPropstat => {
          dPropstat.appendElement('d:prop', '', dProp => {
            dProp
              .appendElement('d:quota-used-bytes', '', '')
              .appendElement('d:quota-available-bytes', '', '')
          }).appendElement('d:status', '', 'HTTP/1.1 404 Not Found')
        })
    })
  }

  const fileVersionPath = version => MatchersV3.regex({
    matcher: `.*\\/remote\\.php\\/dav\\/meta\\/${fileInfo.id}\\/v\\/${fileInfo.versions[version].versionId}$`,
    generate: `/remote.php/dav/meta/${fileInfo.id}/v/${fileInfo.versions[version].versionId}`
  })

  describe.skip('file versions of non existing file', () => {
    it('retrieves file versions of not existing file', async function () {
      const provider = createProvider()
      await getCapabilitiesInteraction(provider)
      await getCurrentUserInformationInteraction(provider)
      await provider
        .uponReceiving('PROPFIND file versions of non existent file')
        .withRequest(propfindFileVersionsRequestData)
        .willRespondWith({
          status: 404,
          headers: applicationXmlResponseHeaders,
          body: new XmlBuilder('1.0', 'utf-8', 'd:error').build(dError => {
            dError.setAttributes({ 'xmlns:d': 'DAV:', 'xmlns:oc': 'http://owncloud.org/ns' })<commit_msg>fix matcher to be correct V3Matcher function call<commit_after>// TODO: Unskip the tests after the issue is fixed
// https://github.com/owncloud/owncloud-sdk/issues/705
import { MatchersV3, XmlBuilder } from '@pact-foundation/pact/v3'

describe('Main: Currently testing file versions management,', function () {
  const config = require('./config/config.json')

  const {
    validAdminAuthHeaders,
    accessControlAllowHeaders,
    accessControlAllowMethods,
    applicationXmlResponseHeaders,
    getContentsOfFileInteraction,
    getCurrentUserInformationInteraction,
    getCapabilitiesInteraction,
    createOwncloud,
    createProvider
  } = require('./pactHelper.js')

  // TESTING CONFIGS
  const versionedFile = config.testFile
  const fileInfo = {
    id: 12345678,
    versions: [
      {
        versionId: 98765432,
        content: config.testContent
      },
      {
        versionId: 87654321,
        content: '*'
      }
    ]
  }
  const propfindFileVersionsRequestData = {
    method: 'PROPFIND',
    path: MatchersV3.regex({
      matcher: `.*\\/remote\\.php\\/dav\\/meta\\/${fileInfo.id}\\/v$`,
      generate: `/remote.php/dav/meta/${fileInfo.id}/v`
    }),
    headers: validAdminAuthHeaders,
    body: new XmlBuilder('1.0', '', 'd:propfind').build(dPropfind => {
      dPropfind.setAttributes({ 'xmlns:d': 'DAV:', 'xmlns:oc': 'http://owncloud.org/ns' })
      dPropfind.appendElement('d:prop', '', '')
    })
  }

  const header = {
    ...applicationXmlResponseHeaders,
    'Access-Control-Allow-Headers': accessControlAllowHeaders,
    'Access-Control-Allow-Methods': accessControlAllowMethods
  }

  const propfindFileVersionsResponse = (node, version, contentLength) => {
    return node.appendElement('d:response', '', dResponse => {
      dResponse.appendElement('d:href', '', `/remote.php/dav/meta/${fileInfo.id}/v/${fileInfo.versions[version].versionId}`)
        .appendElement('d:propstat', '', dPropstat => {
          dPropstat.appendElement('d:prop', '', dProp => {
            dProp
              .appendElement('d:getlastmodified', '', 'Thu, 08 Oct 2020 02:28:50 GMT')
              .appendElement('d:getcontentlength', '', contentLength)
              .appendElement('d:resourcetype', '', '')
              .appendElement('d:getetag', '', '&quot;bc7012325dcc9899be7da7cabfdddb00&quot;')
              .appendElement('d:getcontenttype', '', 'text/plain')
          })
            .appendElement('d:status', '', 'HTTP/1.1 200 OK')
        }).appendElement('d:propstat', '', dPropstat => {
          dPropstat.appendElement('d:prop', '', dProp => {
            dProp
              .appendElement('d:quota-used-bytes', '', '')
              .appendElement('d:quota-available-bytes', '', '')
          }).appendElement('d:status', '', 'HTTP/1.1 404 Not Found')
        })
    })
  }

  const fileVersionPath = version => MatchersV3.regex(
   `.*\\/remote\\.php\\/dav\\/meta\\/${fileInfo.id}\\/v\\/${fileInfo.versions[version].versionId}$`,
   `/remote.php/dav/meta/${fileInfo.id}/v/${fileInfo.versions[version].versionId}`
  )

  describe.skip('file versions of non existing file', () => {
    it('retrieves file versions of not existing file', async function () {
      const provider = createProvider()
      await getCapabilitiesInteraction(provider)
      await getCurrentUserInformationInteraction(provider)
      await provider
        .uponReceiving('PROPFIND file versions of non existent file')
        .withRequest(propfindFileVersionsRequestData)
        .willRespondWith({
          status: 404,
          headers: applicationXmlResponseHeaders,
          body: new XmlBuilder('1.0', 'utf-8', 'd:error').build(dError => {
            dError.setAttributes({ 'xmlns:d': 'DAV:', 'xmlns:oc': 'http://owncloud.org/ns' })
{'fraction_non_alphanumeric': 0.1601702806970866, 'fraction_numerical': 0.0203538645736331, 'mean_word_length': 3.016025641025641, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2940071', 'n_tokens_mistral': 2388, 'n_tokens_neox': 2277, 'n_words': 371}