<commit_before>"use strict"
require('../../test-helper.js') // <--- This must be at the top of every test file.

const Text = require(__app + '/actions/texts');
const pg      = require('../../../db/db_setup');
const dbCleaner = require('knex-cleaner');

describe('Texts model', function() {
  describe('interface with database', function() {

  	beforeEach(function() {
      return dbCleaner.clean(pg, {mode: 'truncate'})
        .then(function() {
          return pg('texts').insert([
            {
              text_id: 1,
              text_content: 'This is an example of Fwibble',
              room_id: 1, 
              user_id: 1,
            },
          ])
        })
    })

    it_('should list all texts of a room', function * () {
      yield Text.allOfRoom(1)
        .then(function(texts) {
          expect(texts).to.have.length(1);
          expect(texts[0].text_content).to.equal('This is an example of Fwibble');
        })
        .catch(function(error) {
          console.error('error inserting text', error)
        })
    })

    it_('should create a new text', function * () {
      let newText = {
        text_content: 'New Fwibble in the database word',
        room_id: 1,
        user_id: 2,
      }

      yield Message.create(newText)
        .then(function(text) {
          expect(text.text_content).to.equal('New Fwibble in the database word');
          expect(text.room_id).to.equal(1);
          expect(text.user_id).to.equal(2);
          expect(text.createdAt).to.be.ok;
        })
        .catch(function(error) {
          console.error('error inserting text', error)
        })
    })
})
})
<commit_msg>Fixed texts test foreign key error, tests pass<commit_after>"use strict"
require('../../test-helper.js') // <--- This must be at the top of every test file.

const Text = require(__app + '/actions/texts');
const pg      = require('../../../db/db_setup');
const dbCleaner = require('knex-cleaner');

describe('Texts model', function() {
  describe('interface with database', function() {

  	beforeEach(function() {
      return dbCleaner.clean(pg, {mode: 'truncate'})
        .then(function() {
          return pg('rooms').insert([
            {
              room_id:1,
              room_hash: 'abc123',
            }
          ])
        })
        .then(function() {
          return pg('users').insert([
            {
              user_id:1,
              username: 'Player1',
              active_room: 1,
            }
          ])
        })
        .then(function(){
          return pg('texts').insert([
            {
              text_id: 1,
              text_content: 'This is an example of Fwibble',
              room_id: 1, 
              user_id: 1,
            },
          ])
        })
    })


    it_('should list all texts of a room', function * () {
      yield Text.allOfRoom(3)
        .then(function(texts) {
          expect(texts).to.have.length(1);
          expect(texts[0].text_content).to.equal('This is an example of Fwibble');
        })
        .catch(function(error) {
          console.error('error inserting text', error)
        })
    })

    it_('should create a new text', function * () {
      let newText = {
        text_content: 'New Fwibble in the database word',
        room_id: 1,
        user_id: 2,
      }

      yield Text.create(newText)
        .then(function(text) {
          expect(text.text_content).to.equal('New Fwibble in the database word');
          expect(text.room_id).to.equal(1);
          expect(text.user_id).to.equal(2);
          expect(text.createdAt).to.be.ok;
        })
        .catch(function(error) {
          console.error('error inserting text', error)
        })
    })
})
})

{'fraction_non_alphanumeric': 0.14728056004308024, 'fraction_numerical': 0.007269789983844911, 'mean_word_length': 1.7848575712143928, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '496839', 'n_tokens_mistral': 1140, 'n_tokens_neox': 1107, 'n_words': 241}