<commit_before>require_relative 'spec_helper'
require 'json'

describe 'Test events services class' do
  before do
    User.dataset.delete
    Event.dataset.delete
  end
  it 'should create an event' do
    # This should create a user and create a event for that user as a host
    new_user = {
      firstName: "Pola",
      lastName: "PinPita",
      email: "<EMAIL>",
      birthday: "1990/07/12",
      country: "Thailand",
      city: "Bangcook",
      password: "<PASSWORD>",
      rating: 3,
      img_path: ""
    }
    new_event = {
      name: "Thai Thai food",
      location: "Hsinchu",
      date: "2017/07/31",
      img_path: "",
      chef: 2,
      helper: 1,
      shopper: 0,
      cleaner: 0,
      guest: 0,
    }

    user = CreateUser.call(new_user)
    user.add_event(new_event)
    user.events.wont_be_nil
  end

  it 'should retrieve a list of events' do
    events = RetrieveEvents.call()
    events.size > 0
  end

  it 'shoudl retrieve a list of events by filter' do
    new_user = {
      firstName: "Pola",
      lastName: "PinPita",
      email: "<EMAIL>",
      birthday: "1990/07/12",
      country: "Thailand",
      city: "Bangcook",
      password: "<PASSWORD>",
      rating: 3,
      img_path: ""
    }
    new_event = {
      name: "Thai Thai food",
      location: "Hsinchu",
      date: "2017/07/31",
      chef: 2,
      helper: 1,
      shopper: 0,
      cleaner: 0,
      guest: 0,
      menus: [{
          name: "<NAME>",
          tags: ["thai","spicy"],
          type: "Halal",
          recipe: "Buy things and <h1>COOK</h1>"
        }],
      img_path: ""
    }

    user = CreateUser.call(new_user)
    event = CreateEvent.call(host_id:user.id,event:new_event)

    events = RetrieveEvents.call(location: "Hsinchu",rating: nil, roles: ["Chef","helper"])
    events.size > 0
  end
end

describe 'Test events api calls' do
  before do
    User.dataset.delete
    Event.dataset.delete
  end
  it 'should create a user and create an event using the api call' do
    req_header = { 'CONTENT_TYPE' => 'application/json' }
    req_body = {
      firstName: "Paul",
      lastName: "Rivera",
      email: "<EMAIL>",
      birthday: "1992/04/12",
      country: "Nicaragua",
      city: "Managua",
      password: "<PASSWORD>",
      rating: 3,
      img_path: ""
    }.to_json
    post '/api/v1/users/', req_body, req_header
    id = _(JSON.parse(last_response.body))['target']['id']

    req_body_event = {
      name: "Thai Thai food",
      location: "Hsinchu",
      date: "2017/07/31",
      chef: 2,
      helper: 1,
      shopper: 0,
      cleaner: 0,
      guest: 0,
      menus: [{
          name: "<NAME>",
          tags: ["thai","spicy"],
          type: "Halal",
          recipe: "Buy things and <h1>COOK</h1>"
        }],
      img_path: ""
    }.to_json
<commit_msg>fixed test structure<commit_after>require_relative 'spec_helper'
require 'json'

describe 'Test events services class' do
  before do
    User.dataset.delete
    Event.dataset.delete
  end
  it 'should create an event' do
    # This should create a user and create a event for that user as a host
    new_user = {
      firstName: "Pola",
      lastName: "PinPita",
      email: "<EMAIL>",
      birthday: "1990/07/12",
      country: "Thailand",
      city: "Bangcook",
      password: "<PASSWORD>",
      rating: 3,
      img_path: ""
    }
    new_event = {
      name: "<NAME>",
      location: "Hsinchu",
      date: "2017/07/31",
      img_path: "",
      chef: 2,
      helper: 1,
      shopper: 0,
      cleaner: 0,
      guest: 0,
    }

    user = CreateUser.call(new_user)
    user.add_event(new_event)
    user.events.wont_be_nil
  end

  it 'should retrieve a list of events' do
    events = RetrieveEvents.call()
    events.size > 0
  end

  it 'shoudl retrieve a list of events by filter' do
    new_user = {
      firstName: "Pola",
      lastName: "PinPita",
      email: "<EMAIL>",
      birthday: "1990/07/12",
      country: "Thailand",
      city: "Bangcook",
      password: "<PASSWORD>",
      rating: 3,
      img_path: ""
    }
    new_event = {
      name: "Thai Thai food",
      location: "Hsinchu",
      date: "2017/07/31 04:00 PM",
      chef: 2,
      helper: 1,
      shopper: 0,
      cleaner: 0,
      guest: 0,
      menus: [{
          name: "<NAME>",
          tags: ["thai","spicy"],
          type: "Halal",
          recipe: "Buy things and <h1>COOK</h1>"
        }],
      img_path: ""
    }

    user = CreateUser.call(new_user)
    event = CreateEvent.call(host_id:user.id,event:new_event)

    events = RetrieveEvents.call(location: "Hsinchu",rating: nil, roles: ["Chef","helper"])
    events.size > 0
  end
end

describe 'Test events api calls' do
  before do
    User.dataset.delete
    Event.dataset.delete
  end
  it 'should create a user and create an event using the api call' do
    req_header = { 'CONTENT_TYPE' => 'application/json' }
    req_body = {
      firstName: "Paul",
      lastName: "Rivera",
      email: "<EMAIL>",
      birthday: "1992/04/12",
      country: "Nicaragua",
      city: "Managua",
      password: "<PASSWORD>",
      rating: 3,
      img_path: ""
    }.to_json
    post '/api/v1/users/', req_body, req_header
    id = _(JSON.parse(last_response.body))['target']['id']

    req_body_event = {
      name: "Thai Thai food",
      location: "Hsinchu",
      date: "2017/07/31 04:00 PM",
      chef: 2,
      helper: 1,
      shopper: 0,
      cleaner: 0,
      guest: 0,
      menus: [{
          name: "<NAME>",
          tags: ["thai","spicy"],
          type: "Halal",
          recipe: "Buy things and <h1>COOK</h1>"
        }],
      img_path: ""
    }.to_json

{'fraction_non_alphanumeric': 0.13930523717157467, 'fraction_numerical': 0.027155704461294304, 'mean_word_length': 2.104542966611932, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 34, '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': '1635975', 'n_tokens_mistral': 2085, 'n_tokens_neox': 1963, 'n_words': 508}