<commit_before>import { suite, test, timeout } from "mocha-typescript";
import * as chai from "chai";
import { Customer } from "../src/entities/Customer";
import { Customers } from "../src/collections/Customers";
import * as PouchDB from "pouchdb";
import * as _ from 'lodash';
import * as metaphone from 'metaphone';

const expect = chai.expect;

@suite("Customer test")
class CustomerTest {

  static db;

  static before() {
    CustomerTest.db = new PouchDB("default");
  }

  static after(done: Function) {
    CustomerTest.db.destroy(() => done());
  }

  @test("should return correct prefix")
  public testPrefix() {
    const customers = new Customers(CustomerTest.db, Customer);
    expect(customers.getPrefix()).to.equal("customer");
  }
  //Insertion  
  @test("should insert customer with mobile")
  public testInsertMobile(done) {
    const customers = new Customers(CustomerTest.db, Customer);
    customers.insert({ mobile: "6465490561" }).then((c) => {
      expect(c.mobile).to.equal("6465490561");
      done();
    }).catch(_.noop);
  }

  @test("should insert all parameters")
  public testInsertAll(done) {
    let customerObj = {
      mobile: "19292778399",
      name: "<NAME>",
      email: "<EMAIL>",
      autocomplete: "199 Orchard St, New York, NY 10002, USA",
      street_num: "199",
      street_route: "Orchard Street",
      apartment: "2D",
      city: "New York",
      state: "NY",
      zip: "10002",
      lat: "40.72224",
      lng: "-73.988152",
      is_doorman: true,
      delivery_notes: "Ring bell twice",
      cleaning_notes: "Clean slowly",
      payment_customer_id: "cus_9xJOnv9Enc98S",
      payment_customer_token: "<PASSWORD>"
    }
    const customers = new Customers(CustomerTest.db, Customer);
    customers.insert(customerObj).then((c) => {
      _.forIn(customerObj, function(value, key) {
        expect(c[key]).to.equal(value);
      })
      done();
    }).catch(_.noop);
  }

  //Search
  @test("should be searchable by mobile")
  public testSearchMobile(done) {
    const customers = new Customers(CustomerTest.db, Customer);
    customers.insert({ mobile: "6465490562" }).then((c) => {
      return customers.find("mobile", "6465490562")
    }).then((cs) => {
      expect(cs.length).to.equal(1);
      expect(cs[0].mobile).to.equal("6465490562");
      done();
    }).catch(_.noop);
  }

  @test("should be searchable by last4")
  public testSearchLast4(done) {
    const customers = new Customers(CustomerTest.db, Customer);
    customers.insert({ mobile: "6465490563" }).then((c) => {
      return customers.find("mobile", "0563")
    }).then((cs) => {
      expect(cs.length).to.equal(1);
      expect(cs[0].mobile).to.equal("6465490563");
      done();
    }).catch(_.noop);
  }

  @test("should be searchable by metaphone")
  public testSearchName(done) {
    const customers = new Customers(CustomerTest.db, Customer);
    customers.insert({ name: "<NAME>", mobile: "6465490564" }).then((c) => {
      return customers.findByName("<NAME>");
    }).then((cs) => {
      expect(cs.length).to.equal(1);
      expect(cs[0].name).to.equal("<NAME>");
      done();
    }).catch(_.noop);
  }

  @test("should be searchable by name")
  public testSearchMetaphone(done) {
    const customers = new Customers(CustomerTest.db, Customer);
    customers.insert({ name: "<NAME>", mobile: "6465490565" }).then((c) => {
      return customers.find("name", "<NAME>");
    }).then((cs) => {
      expect(cs.length).to.equal(1);
      expect(cs[0].name).to.equal("<NAME>");
      done();
    }).catch(_.noop);
  }

  //Update
  @test("should update parameters")
  public testUpdate(done) {
    let customerObj = {
      mobile: "19292778391",
      name: "<NAME>",
      email: "<EMAIL>",
      autocomplete: "199 Orchard St, New York, NY 10002, USA",
      street_num: "199",
      street_route: "Orchard Street",<commit_msg>Test paginate<commit_after>import { suite, test, timeout } from "mocha-typescript";
import * as chai from "chai";
import { Customer } from "../src/entities/Customer";
import { Customers } from "../src/collections/Customers";
import * as PouchDB from "pouchdb";
import * as _ from 'lodash';
import * as metaphone from 'metaphone';

const expect = chai.expect;

@suite("Customer test")
class CustomerTest {

  static db;

  static before() {
    CustomerTest.db = new PouchDB("default");
  }

  static after(done: Function) {
    CustomerTest.db.destroy(() => done());
  }

  @test("should return correct prefix")
  public testPrefix() {
    const customers = new Customers(CustomerTest.db, Customer);
    expect(customers.getPrefix()).to.equal("customer");
  }
  //Insertion  
  @test("should insert customer with mobile")
  public testInsertMobile(done) {
    const customers = new Customers(CustomerTest.db, Customer);
    customers.insert({ mobile: "6465490561" }).then((c) => {
      expect(c.mobile).to.equal("6465490561");
      done();
    }).catch(_.noop);
  }

  @test("should insert all parameters")
  public testInsertAll(done) {
    let customerObj = {
      mobile: "19292778399",
      name: "<NAME>",
      email: "<EMAIL>",
      autocomplete: "199 Orchard St, New York, NY 10002, USA",
      street_num: "199",
      street_route: "Orchard Street",
      apartment: "2D",
      city: "New York",
      state: "NY",
      zip: "10002",
      lat: "40.72224",
      lng: "-73.988152",
      is_doorman: true,
      delivery_notes: "Ring bell twice",
      cleaning_notes: "Clean slowly",
      payment_customer_id: "cus_9xJOnv9Enc98S",
      payment_customer_token: "<PASSWORD>"
    }
    const customers = new Customers(CustomerTest.db, Customer);
    customers.insert(customerObj).then((c) => {
      _.forIn(customerObj, function(value, key) {
        expect(c[key]).to.equal(value);
      })
      done();
    }).catch(_.noop);
  }

  //Search
  @test("should be searchable by mobile")
  public testSearchMobile(done) {
    const customers = new Customers(CustomerTest.db, Customer);
    customers.insert({ mobile: "6465490562" }).then((c) => {
      return customers.find("mobile", "6465490562")
    }).then((cs) => {
      expect(cs.length).to.equal(1);
      expect(cs[0].mobile).to.equal("6465490562");
      done();
    }).catch(_.noop);
  }

  @test("should be searchable by last4")
  public testSearchLast4(done) {
    const customers = new Customers(CustomerTest.db, Customer);
    customers.insert({ mobile: "6465490563" }).then((c) => {
      return customers.find("mobile", "0563")
    }).then((cs) => {
      expect(cs.length).to.equal(1);
      expect(cs[0].mobile).to.equal("6465490563");
      done();
    }).catch(_.noop);
  }

  @test("should be searchable by metaphone")
  public testSearchName(done) {
    const customers = new Customers(CustomerTest.db, Customer);
    customers.insert({ name: "<NAME>", mobile: "6465490564" }).then((c) => {
      return customers.findByName("<NAME>");
    }).then((cs) => {
      expect(cs.length).to.equal(1);
      expect(cs[0].name).to.equal("<NAME>");
      done();
    }).catch(_.noop);
  }

  @test("should be searchable by name")
  public testSearchMetaphone(done) {
    const customers = new Customers(CustomerTest.db, Customer);
    customers.insert({ name: "<NAME>", mobile: "6465490565" }).then((c) => {
      return customers.find("name", "<NAME>");
    }).then((cs) => {
      expect(cs.length).to.equal(1);
      expect(cs[0].name).to.equal("<NAME>");
      done();
    }).catch(_.noop);
  }

  @test("should be possible to paginate")
  public testSearchPaginate(done) {
    const customers = new Customers(CustomerTest.db, Customer);
    customers.insert({ name: "<NAME>", mobile: "6465490555" }).then((c) => {
      return customers.insert({ name: "<NAME>", mobile: "6165490555" });
    }).then((cs) => {
      return customers.insert({ name: "<NAME>", mobile: "6225490555" });
    }).then((cs) => {
      return customers.find("mobile", "0555")
    }).then((custs) => {
      expect(custs.length).to.equal(3);
      expect(custs[0].name).to.equal("Boo Gan1");
      expect(custs[1].name).to.equal("Boo Gan2");
      expect(custs[2].name).to.equal("Boo Gan3");
      return customers.find("mobile", "0555", {limit: 2});
    }).then((custs2) => {
      expect(custs2[0].name).to.equal("Boo Gan1");
      expect(custs2[1].name).to.equal("Boo Gan2");
      expect(custs2.length).to.equal(2);
      return customers.find("mobile", "0555", {limit: 1});
    }).then((custs1) => {
      expect(custs1.length).to.equal(1);
      expect(custs1[0].name).to.equal("Boo Gan1");
      return customers.find("mobile", "0555", {limit: 1, skip: 2});
    }).then((custs1) => {
      expect(custs1.length).to.equal(1);
      expect(custs1[0].name).to.equal("Boo Gan3");
      done();
    }).catch(_.noop);
  }

  //Update
  @test("should update parameters")
  public testUpdate(done) {
    let customerObj = {
      mobile: "19292778391",
      name: "<NAME>",
      email: "<EMAIL>",
      autocomplete: "199 Orchard St, New York, NY 10002, USA",
      street_num: "199",
      street_route: "Orchard Street",
{'fraction_non_alphanumeric': 0.18002207505518764, 'fraction_numerical': 0.046799116997792496, 'mean_word_length': 3.2983870967741935, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2720281', 'n_tokens_mistral': 3248, 'n_tokens_neox': 2988, 'n_words': 632}