mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-25 14:28:51 +08:00
refactor: init package @affine/workspace (#1661)
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import { getDefaultStore } from 'jotai';
|
||||
import { describe, expect, test } from 'vitest';
|
||||
|
||||
import { currentAffineUserAtom } from '../atom';
|
||||
|
||||
describe('atom', () => {
|
||||
test('currentAffineUserAtom', () => {
|
||||
const store = getDefaultStore();
|
||||
const mock = {
|
||||
created_at: 0,
|
||||
exp: 0,
|
||||
email: '',
|
||||
id: '',
|
||||
name: '',
|
||||
avatar_url: '',
|
||||
};
|
||||
store.set(currentAffineUserAtom, mock);
|
||||
expect(store.get(currentAffineUserAtom)).toEqual(mock);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* @vitest-environment happy-dom
|
||||
*/
|
||||
import type { AccessTokenMessage } from '@affine/workspace/affine/login';
|
||||
import {
|
||||
getLoginStorage,
|
||||
isExpired,
|
||||
setLoginStorage,
|
||||
STORAGE_KEY,
|
||||
} from '@affine/workspace/affine/login';
|
||||
import { describe, expect, test } from 'vitest';
|
||||
|
||||
describe('storage', () => {
|
||||
test('should work', () => {
|
||||
setLoginStorage({
|
||||
token: '1',
|
||||
refresh: '2',
|
||||
});
|
||||
const data = localStorage.getItem(STORAGE_KEY);
|
||||
expect(data).toBe('{"token":"1","refresh":"2"}');
|
||||
const login = getLoginStorage();
|
||||
expect(login).toEqual({
|
||||
token: '1',
|
||||
refresh: '2',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('utils', () => {
|
||||
test('isExpired', async () => {
|
||||
const now = Math.floor(Date.now() / 1000);
|
||||
expect(isExpired({ exp: now + 1 } as AccessTokenMessage)).toBeFalsy();
|
||||
const promise = new Promise<void>(resolve => {
|
||||
setTimeout(() => {
|
||||
expect(isExpired({ exp: now + 1 } as AccessTokenMessage)).toBeTruthy();
|
||||
resolve();
|
||||
}, 2000);
|
||||
});
|
||||
expect(isExpired({ exp: now - 1 } as AccessTokenMessage)).toBeTruthy();
|
||||
await promise;
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user