liststorage.tests.js 2.02 KB
Newer Older
Yaxel Perez's avatar
Yaxel Perez committed
1 2
// (function (jIO, RSVP, QUnit) {
(function (jIO, QUnit) {
Yaxel Perez's avatar
.  
Yaxel Perez committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16
  "use strict";

  QUnit.module("ListStorage");

  QUnit.test('Constructor does not crash', function () {
    jIO.createJIO({
      type: "list",
      sub_storage: {
        type: "memory"
      }
    });
    QUnit.expect(0);
  });

Yaxel Perez's avatar
Yaxel Perez committed
17 18 19
  // NOTE: list method is implicitly tested in the following two methods

  QUnit.test('post method correctly records ids', function (assert) {
20 21 22 23 24 25 26
    QUnit.stop();
    QUnit.expect(1);

    var jio = jIO.createJIO({
      type: 'list',
      sub_storage: {
        type: 'uuid',
Yaxel Perez's avatar
.  
Yaxel Perez committed
27
        sub_storage: {
28
          type: 'memory'
Yaxel Perez's avatar
.  
Yaxel Perez committed
29
        }
30
      }
Yaxel Perez's avatar
Yaxel Perez committed
31
    });
Yaxel Perez's avatar
.  
Yaxel Perez committed
32

Yaxel Perez's avatar
Yaxel Perez committed
33 34 35
    jio.post({}).then(function (id1) {
      jio.post({}).then(function (id2) {
        jio.list().then(function (l) {
36
          QUnit.start();
Yaxel Perez's avatar
Yaxel Perez committed
37
          assert.deepEqual(l, [id1, id2]);
38
        });
Yaxel Perez's avatar
Yaxel Perez committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
      });
    }).fail(console.error);
  });

  QUnit.test('put method correctly records ids', function (assert) {
    QUnit.stop();
    QUnit.expect(1);

    var jio = jIO.createJIO({
      type: 'list',
      sub_storage: {
        type: 'uuid',
        sub_storage: {
          type: 'memory'
        }
54 55
      }
    });
Yaxel Perez's avatar
Yaxel Perez committed
56 57 58 59 60 61 62 63 64

    jio.put('test', {}).then(function (id1) {
      jio.put('test2', {}).then(function (id2) {
        jio.list().then(function (l) {
          QUnit.start();
          assert.deepEqual(l, [id1, id2]);
        });
      });
    }).fail(console.error);
65
  });
Yaxel Perez's avatar
.  
Yaxel Perez committed
66

Yaxel Perez's avatar
Yaxel Perez committed
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
  QUnit.test('remove method correctly removes id', function (assert) {
    QUnit.stop();
    QUnit.expect(1);

    var jio = jIO.createJIO({
      type: 'list',
      sub_storage: {
        type: 'uuid',
        sub_storage: {
          type: 'memory'
        }
      }
    });

    jio.put('test', {}).then(function () {
      jio.put('test2', {}).then(function () {
        jio.remove('test').then(function () {
          jio.list().then(function (l2) {
            QUnit.start();
            assert.deepEqual(l2, ['test2']);
          });
        });
      });
    }).fail(console.error);
  });

Yaxel Perez's avatar
Yaxel Perez committed
93 94
// }(jIO, RSVP, QUnit));
}(jIO, QUnit));