<commit_before>import { Dispatcher } from 'consus-core/flux';
import CartStore from '../../../.dist/store/cart-store';
import { assert } from 'chai';

describe('CartStore', () => {

    beforeEach(() => {
        return Dispatcher.handleAction('CLEAR_ALL_DATA');
    });

    it('should instantiate without any items', () => {
        assert.strictEqual(CartStore.getItems().length, 0);
    });

    it('should add item to list', () => {
        Dispatcher.handleAction('CHECKOUT_ITEM_FOUND',{
            address: '123',
            status: 'AVAILABLE'
        });
        assert.strictEqual(CartStore.getItems()[0].address, '123');
        assert.strictEqual(CartStore.getItems()[0].status, 'AVAILABLE');
    });

    it('should clear items on checkout',() => {
        Dispatcher.handleAction('STUDENT_FOUND', {
            id: '123456',
            name: '<NAME>',
            items: []
        });
        Dispatcher.handleAction('CHECKOUT_ITEM_FOUND',{
            address: '123',
            status: 'AVAILABLE'
        });
        assert.strictEqual(CartStore.getItems()[0].address, '123');
        Dispatcher.handleAction('CHECKOUT_SUCCESS');
        assert.strictEqual(CartStore.getItems().length,0);
    });

    it('should clear items on cancel', () => {
      Dispatcher.handleAction('STUDENT_FOUND', {
          id: '123456',
          name: '<NAME>',
          items: []
      });
      Dispatcher.handleAction('CHECKOUT_ITEM_FOUND',{
          address: '123',
          status: 'AVAILABLE'
      });
      assert.strictEqual(CartStore.getItems()[0].address, '123');
      Dispatcher.handleAction('CLEAR_ITEMS');
      assert.strictEqual(CartStore.getItems().length,0);
    });

});<commit_msg>Started testing timeout stuff<commit_after>import { Dispatcher } from 'consus-core/flux';
import CartStore from '../../../.dist/store/cart-store';
import StudentStore from '../../../.dist/store/student-store';
import { assert } from 'chai';

describe('CartStore', () => {

    beforeEach(() => {
        return Dispatcher.handleAction('CLEAR_ALL_DATA');
    });

    it('should instantiate without any items', () => {
        assert.strictEqual(CartStore.getItems().length, 0);
    });

    it('should add item to list', () => {
        Dispatcher.handleAction('CHECKOUT_ITEM_FOUND',{
            address: '123',
            status: 'AVAILABLE'
        });
        assert.strictEqual(CartStore.getItems()[0].address, '123');
        assert.strictEqual(CartStore.getItems()[0].status, 'AVAILABLE');
    });

    it('should clear items on checkout',() => {
        Dispatcher.handleAction('STUDENT_FOUND', {
            id: '123456',
            name: '<NAME>',
            items: []
        });
        Dispatcher.handleAction('CHECKOUT_ITEM_FOUND',{
            address: '123',
            status: 'AVAILABLE'
        });
        assert.strictEqual(CartStore.getItems()[0].address, '123');
        Dispatcher.handleAction('CHECKOUT_SUCCESS');
        assert.strictEqual(CartStore.getItems().length,0);
    });

    it('should clear items on cancel', () => {
      Dispatcher.handleAction('STUDENT_FOUND', {
          id: '123456',
          name: '<NAME>',
          items: []
      });
      Dispatcher.handleAction('CHECKOUT_ITEM_FOUND',{
          address: '123',
          status: 'AVAILABLE'
      });
      assert.strictEqual(CartStore.getItems()[0].address, '123');
      Dispatcher.handleAction('CLEAR_ITEMS');
      assert.strictEqual(CartStore.getItems().length,0);
    });

    it('times out', function(done) {
        Dispatcher.handleAction("STUDENT_FOUND", {
            id: '111111',
            name: 'Poe',
            items: []
        });
        assert.isFalse(CartStore.isOnTimeout());
        //shorten timeout time so tests don't just take a minute longer
        CartStore.TIMEOUT_TIME = 100;
        Dispatcher.handleAction('CHECKOUT_ITEM_FOUND',{
            address: '123',
            status: 'AVAILABLE'
        });
        
        setTimeout(() => {
            assert.isFalse(CartStore.isOnTimeout());
            done();
        }, CartStore.TIMEOUT_TIME + 1000);

        // assert.strictEqual(StudentStore.getStudent().items.length, 1);
        // assert.strictEqual(CartStore.getItems().length,0);
    });

    it('cancels timeout when new student is scanned', () => {
        Dispatcher.handleAction("STUDENT_FOUND", {
            id: '111111',
            name: 'Poe',
            items: []
        });
        assert.isFalse(CartStore.isOnTimeout());
        CartStore.TIMEOUT_TIME = 60000;
        Dispatcher.handleAction('CHECKOUT_ITEM_FOUND',{
            address: '123',
            status: 'AVAILABLE'
        });
        assert.isTrue(CartStore.isOnTimeout());
        Dispatcher.handleAction("STUDENT_FOUND", {
            id: '123432',
            name: '<NAME>',
            items: []
        });
        assert.isFalse(CartStore.isOnTimeout());
    });

});
{'fraction_non_alphanumeric': 0.16113936927772127, 'fraction_numerical': 0.022787385554425228, 'mean_word_length': 2.3171390013495277, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 22, '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': '1052424', 'n_tokens_mistral': 1530, 'n_tokens_neox': 1406, 'n_words': 226}