<commit_before>expect      = require 'expect.js'
_           = require 'underscore'
async       = require 'async'
mongoose    = require 'mongoose'
config      = require '../../../test/test_config'
common      = require '../../../test/common'
api_methods = require("../../../lib/api_methods")(config)
www_schema  = require('../../../lib/schema').load(config)
tp_schema   = require("../lib/schema").load(config)
padlib      = require("../lib/padlib")(config)

timeoutSet = (a, b) -> setTimeout(b, a)

skip_tests = process.env.SKIP_ETHERPAD_TESTS

delete_all_test_pads = (callback) ->
  tp_schema.TwinklePad.find (err, docs) ->
    async.map docs, (doc, done) ->
      if doc.pad_name.substring(0, "tptest_".length) == "tptest_"
        padlib.delete_pad(doc, done)
      else
        done()
    , callback

describe "padlib", ->
  before (done) ->
    return done() if skip_tests
    async.series [
      (done) ->
        require("../bin/resync_etherpad_ids").run config, done

      (done) ->
        db = mongoose.connect(
          "mongodb://#{config.dbhost}:#{config.dbport}/#{config.dbname}"
        )
        delete_all_test_pads ->
          db.disconnect(done)

      (done) =>
        common.startUp (server) =>
          @server = server
          done()
    ], done

  after (done) ->
    return done() if skip_tests
    delete_all_test_pads =>
      common.shutDown(@server, done)

  it "Saves a pad", (done) ->
    return done() if skip_tests
    pad = new tp_schema.TwinklePad(pad_name: "tptest_1")
    pad.save (err, doc) -><commit_msg>Add test for special chars in pad<commit_after>expect      = require 'expect.js'
_           = require 'underscore'
async       = require 'async'
mongoose    = require 'mongoose'
config      = require '../../../test/test_config'
common      = require '../../../test/common'
api_methods = require("../../../lib/api_methods")(config)
www_schema  = require('../../../lib/schema').load(config)
tp_schema   = require("../lib/schema").load(config)
padlib      = require("../lib/padlib")(config)

timeoutSet = (a, b) -> setTimeout(b, a)

skip_tests = process.env.SKIP_ETHERPAD_TESTS

delete_all_test_pads = (callback) ->
  tp_schema.TwinklePad.find (err, docs) ->
    async.map docs, (doc, done) ->
      if doc.pad_name.substring(0, "tptest_".length) == "tptest_"
        padlib.delete_pad(doc, done)
      else
        done()
    , callback

describe "padlib", ->
  before (done) ->
    return done() if skip_tests
    async.series [
      (done) ->
        require("../bin/resync_etherpad_ids").run config, done

      (done) ->
        db = mongoose.connect(
          "mongodb://#{config.dbhost}:#{config.dbport}/#{config.dbname}"
        )
        delete_all_test_pads ->
          db.disconnect(done)

      (done) =>
        common.startUp (server) =>
          @server = server
          done()
    ], done

  after (done) ->
    return done() if skip_tests
    delete_all_test_pads =>
      common.shutDown(@server, done)

  it "Saves a pad", (done) ->
    return done() if skip_tests
    pad = new tp_schema.TwinklePad(pad_name: "tptest_1")
    pad.save (err, doc) ->
      expect(err).to.be(null)
      expect(doc.read_only_pad_id).to.not.be(null)
      done()

  it "Saves a pad with special chars", (done) ->
    pad = new tp_schema.TwinklePad(pad_name: "test/url&chars%'=")
    pad.save (err, doc) ->
{'fraction_non_alphanumeric': 0.16641857695742782, 'fraction_numerical': 0.0011908306043465317, 'mean_word_length': 2.4215885947046845, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, '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': '401605', 'n_tokens_mistral': 1148, 'n_tokens_neox': 1141, 'n_words': 226}