<commit_before>import ItemStore from '../../../.dist/store/item-store';
import ModelStore from '../../../.dist/store/model-store';
import StudentStore from '../../../.dist/store/student-store';
import { assert } from 'chai';
import { addAction } from '../../util/database';

describe('ItemStore', () => {

    let student;
    let model;
    let items = [];

    beforeEach(() => {
        return addAction('CLEAR_ALL_DATA').then(() => {
            return addAction('NEW_MODEL', {
                name: 'Resistor'
            });
        }).then(actionId => {
            model = ModelStore.getModelByActionId(actionId);
            return addAction('NEW_STUDENT', {
                id: '123456',
                name: '<NAME>'
            });
        }).then(actionId => {
            student = StudentStore.getStudentByActionId(actionId);
            return addAction('NEW_ITEM', {
                modelAddress: model.address
            });
        }).then(() => {
            return addAction('NEW_ITEM', {
                modelAddress: model.address
            });
        }).then(() => {
            items = ItemStore.getItems();
        });
    });

    it('should clear all data', () => {
        return addAction('CLEAR_ALL_DATA').then(() => {
            assert.lengthOf(ItemStore.getItems(), 0);
        });
    });

    it('should create an item', () => {
        return addAction('NEW_ITEM', {
            modelAddress: model.address
        }).then(actionId => {
            items.push(ItemStore.getItemByActionId(actionId));
            assert.lengthOf(ItemStore.getItems(), 3);
        });
    });

    it('should create more items', () => {
        return addAction('NEW_ITEM', {
            modelAddress: model.address
        }).then(actionId => {
            items.push(ItemStore.getItemByActionId(actionId));
            return addAction('NEW_ITEM', {
                modelAddress: model.address
            });
        }).then(actionId => {
            items.push(ItemStore.getItemByActionId(actionId));
            assert.lengthOf(ItemStore.getItems(), 4);
        });
    });

    it('should check out multiple items', () => {
        return addAction('NEW_CHECKOUT', {
            studentId: student.id,
            equipmentAddresses: [items[0].address, items[1].address]
        }).then(() => {
            assert.strictEqual(items[0].status, 'CHECKED_OUT');
            assert.strictEqual(items[1].status, 'CHECKED_OUT');
        });
    });

    it('should check an item in', () => {
        return addAction('CHECKIN', {
            studentId: student.id,
            itemAddress: items[0].address
        }).then(() => {
            assert.strictEqual(items[0].status, 'AVAILABLE');
        });
    });

    it('should fail to delete an item', () =>{
        assert.strictEqual(items.length, 2);
        return addAction('DELETE_ITEM', {
            itemAddress: 'This is not an address'
        }).then(assert.fail)
          .catch(e => {
              assert.strictEqual(e.message, 'Unknown type.');
              assert.strictEqual(items.length, 2);
          });
    });

    it('should delete an item', () =>{
        assert.strictEqual(items.length, 2);
        let deletedItemAddress = items[0].address;
        let modelAddress = items[0].modelAddress;<commit_msg>Fixed a test that I have no clue how I broke.<commit_after>import ItemStore from '../../../.dist/store/item-store';
import ModelStore from '../../../.dist/store/model-store';
import StudentStore from '../../../.dist/store/student-store';
import { assert } from 'chai';
import { addAction } from '../../util/database';

describe('ItemStore', () => {

    let student;
    let model;
    let items = [];

    beforeEach(() => {
        return addAction('CLEAR_ALL_DATA').then(() => {
            return addAction('NEW_MODEL', {
                name: 'Resistor'
            });
        }).then(actionId => {
            model = ModelStore.getModelByActionId(actionId);
            return addAction('NEW_STUDENT', {
                id: '123456',
                name: '<NAME>'
            });
        }).then(actionId => {
            student = StudentStore.getStudentByActionId(actionId);
            return addAction('NEW_ITEM', {
                modelAddress: model.address
            });
        }).then(() => {
            return addAction('NEW_ITEM', {
                modelAddress: model.address
            });
        }).then(() => {
            items = ItemStore.getItems();
        });
    });

    it('should clear all data', () => {
        return addAction('CLEAR_ALL_DATA').then(() => {
            assert.lengthOf(ItemStore.getItems(), 0);
        });
    });

    it('should create an item', () => {
        return addAction('NEW_ITEM', {
            modelAddress: model.address
        }).then(actionId => {
            items.push(ItemStore.getItemByActionId(actionId));
            assert.lengthOf(ItemStore.getItems(), 3);
        });
    });

    it('should create more items', () => {
        return addAction('NEW_ITEM', {
            modelAddress: model.address
        }).then(actionId => {
            items.push(ItemStore.getItemByActionId(actionId));
            return addAction('NEW_ITEM', {
                modelAddress: model.address
            });
        }).then(actionId => {
            items.push(ItemStore.getItemByActionId(actionId));
            assert.lengthOf(ItemStore.getItems(), 4);
        });
    });

    it('should check out multiple items', () => {
        return addAction('NEW_CHECKOUT', {
            studentId: student.id,
            equipmentAddresses: [items[0].address, items[1].address]
        }).then(() => {
            assert.strictEqual(items[0].status, 'CHECKED_OUT');
            assert.strictEqual(items[1].status, 'CHECKED_OUT');
        });
    });

    it('should check an item in', () => {
        return addAction('CHECKIN', {
            studentId: student.id,
            itemAddress: items[0].address
        }).then(() => {
            assert.strictEqual(items[0].status, 'AVAILABLE');
        });
    });

    it('should fail to delete an item', () =>{
        assert.strictEqual(items.length, 2);
        let modelAddress = items[0].modelAddress;
        return addAction('DELETE_ITEM', {
            itemAddress: 'This is not an address',
            modelAddress: modelAddress
        }).then(assert.fail)
          .catch(e => {
              assert.strictEqual(e.message, 'Unknown type.');
              assert.strictEqual(items.length, 2);
          });
    });

    it('should delete an item', () =>{
        assert.strictEqual(items.length, 2);
        let deletedItemAddress = items[0].address;
        let modelAddress = items[0].modelAddress;
{'fraction_non_alphanumeric': 0.1600831600831601, 'fraction_numerical': 0.006088506088506088, 'mean_word_length': 1.901766479965532, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 47, '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': '2987995', 'n_tokens_mistral': 1861, 'n_tokens_neox': 1823, 'n_words': 338}