Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Storage.spec.ts « test - github.com/jsxc/jsxc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 08678a11ec856d9d9cb5c29bc519049e3482d48e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { expect } from 'chai';
import * as sinon from 'sinon';
import 'mocha';

import Storage from '@src/Storage'

describe('Storage', function() {
    let storage;

    before(function() {
        storage = new Storage();
    })

    after(function() {
        storage.getBackend().clear();
    })

    it('should mark storage as not conform');

    it('should mark storage as conform');

    it('should return the right prefix', function() {
        expect(storage.getPrefix()).equals('jsxc2:');
    })

    it('should properly generate keys', function() {
        expect(storage.generateKey('foo')).equals('foo');
        expect(storage.generateKey('foo', 'bar')).equals('foo:bar');
        expect(storage.generateKey('foo', 'bar', '1')).equals('foo:bar:1');
        expect(storage.generateKey('foo', 'bar', '1', '2')).equals('foo:bar:1:2');
    })

    it('should save key/value pairs', function() {
        let data = [
            { foo: 'bar' },
            { foo: true },
            { foo: { foo: 'bar' } }
        ];

        let spy = sinon.spy(storage.getBackend(), 'setItem');

        data.forEach(function(pair, index) {
            let key = Object.keys(pair)[0];
            let value = pair[key];

            storage.setItem(key, value);

            let expectedStoredValue = value;

            if (typeof value === 'object') {
                expectedStoredValue = JSON.stringify(value);
            }

            expect(spy.args[index][0]).equals('jsxc2:' + key);
            expect(spy.args[index][1]).equals(expectedStoredValue);
        });
    })

    it('should save key/value pairs of a specific type')

    it('should properly retrieve key/value pairs')

    it('should properly retrieve key/value pairs of a specific type')
});