mirror of
https://github.com/directus/directus.git
synced 2026-02-07 15:44:56 -05:00
* Declare return types on functions And a very few other type related minor fixes * Minor syntax fixes * Remove unnecessary escape chars in regexes * Remove unnecessary awaits * Replace deprecated req.connection with req.socket * Replace deprecated upload with uploadOne * Remove unnecessary eslint-disable-next-line comments * Comment empty functions / catch or finally clauses * Fix irregular whitespaces * Add missing returns (null) * Remove unreachable code * A few logical fixes * Remove / Handle non-null assertions which are certainly unnecessary (e.g. in tests)
90 lines
2.2 KiB
TypeScript
90 lines
2.2 KiB
TypeScript
import { IStorage } from '../../../src/storage';
|
|
|
|
export function createStorageTests(createStorage: () => IStorage) {
|
|
return function (): void {
|
|
beforeEach(() => {
|
|
// These run both in node and browser mode
|
|
if (typeof localStorage !== 'undefined') {
|
|
localStorage.clear();
|
|
}
|
|
});
|
|
|
|
it('set returns the same value', async function () {
|
|
const storage = createStorage();
|
|
|
|
const value = storage.set('value', '1234');
|
|
expect(value).toBe('1234');
|
|
});
|
|
|
|
it('get returns previously set items', async function () {
|
|
const storage = createStorage();
|
|
|
|
storage.set('value1', '1234');
|
|
const value1 = storage.get('value1');
|
|
expect(value1).toBe('1234');
|
|
|
|
storage.set('value2', 'string');
|
|
const value2 = storage.get('value2');
|
|
expect(value2).toBe('string');
|
|
|
|
storage.set('value3', 'false');
|
|
const value3 = storage.get('value3');
|
|
expect(value3).toBe('false');
|
|
});
|
|
|
|
it('get returns null for missing items', async function () {
|
|
const storage = createStorage();
|
|
|
|
const value = storage.get('value');
|
|
expect(value).toBeNull();
|
|
});
|
|
|
|
it('delete removes items and returns it', async function () {
|
|
const storage = createStorage();
|
|
|
|
let value = storage.get('abobrinha');
|
|
expect(value).toBeNull();
|
|
|
|
value = storage.set('value', '12345');
|
|
expect(value).toBe('12345');
|
|
|
|
value = storage.delete('value');
|
|
expect(value).toBe('12345');
|
|
|
|
value = storage.get('value');
|
|
expect(value).toBeNull();
|
|
});
|
|
|
|
it('delete returns null if removing an unknown key', async function () {
|
|
const storage = createStorage();
|
|
|
|
const value = storage.delete('unknown');
|
|
expect(value).toBeNull();
|
|
});
|
|
|
|
it('can get and set auth_token', async function () {
|
|
const storage = createStorage();
|
|
|
|
expect(storage.auth_token).toBeNull();
|
|
|
|
storage.auth_token = '12345';
|
|
expect(storage.auth_token).toBe('12345');
|
|
|
|
storage.auth_token = null;
|
|
expect(storage.auth_token).toBeNull();
|
|
});
|
|
|
|
it('can get and set auth_expires', async function () {
|
|
const storage = createStorage();
|
|
|
|
expect(storage.auth_expires).toBeNull();
|
|
|
|
storage.auth_expires = 12345;
|
|
expect(storage.auth_expires).toBe(12345);
|
|
|
|
storage.auth_expires = null;
|
|
expect(storage.auth_expires).toBeNull();
|
|
});
|
|
};
|
|
}
|