mirror of
https://github.com/balzack/databag.git
synced 2025-04-24 10:35:23 +00:00
testing identity module
This commit is contained in:
parent
f8299dd78a
commit
d3dbeb5ffa
@ -20,7 +20,7 @@ export class MockIdentityModule implements Identity {
|
||||
this.emitter.off('profile', ev);
|
||||
}
|
||||
|
||||
public close(): void {
|
||||
public async close(): Promise<void> {
|
||||
}
|
||||
|
||||
public async setRevision(rev: number): Promise<void> {
|
||||
@ -33,7 +33,8 @@ export class MockIdentityModule implements Identity {
|
||||
public async setProfileImage(image: string): Promise<void> {
|
||||
}
|
||||
|
||||
public async getHandleStatus(handle: string): Promise<void> {
|
||||
public async getHandleStatus(handle: string): Promise<boolean> {
|
||||
return false;
|
||||
}
|
||||
|
||||
public getProfileImageUrl(): string {
|
||||
|
@ -28,7 +28,7 @@ export interface Logging {
|
||||
}
|
||||
|
||||
export interface Session {
|
||||
close(): { node: string, secure: boolean, token: string };
|
||||
close(): Promise<{ node: string, secure: boolean, token: string }>;
|
||||
|
||||
getAccount(): Account;
|
||||
getIdentity(): Identity;
|
||||
@ -81,7 +81,7 @@ export interface Account {
|
||||
export interface Identity {
|
||||
setProfileData(name: string, location: string, description: string): Promise<void>;
|
||||
setProfileImage(image: string): Promise<void>;
|
||||
getHandleStatus(handle: string): Promise<void>;
|
||||
getHandleStatus(handle: string): Promise<boolean>;
|
||||
|
||||
getProfileImageUrl(): string;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import type { Seal, Profile } from './types';
|
||||
import type { Profile } from './types';
|
||||
|
||||
export type CardEntity = {
|
||||
id: string,
|
||||
@ -142,6 +142,13 @@ export type ArticleEntity = {
|
||||
}
|
||||
}
|
||||
|
||||
export type SealEntity = {
|
||||
passwordSalt: string,
|
||||
privateKeyIv: string,
|
||||
privateKeyEncrypted: string,
|
||||
publicKey: string,
|
||||
}
|
||||
|
||||
export type AccountEntity = {
|
||||
disabled: boolean,
|
||||
storageUsed: number,
|
||||
@ -151,7 +158,7 @@ export type AccountEntity = {
|
||||
allowUnsealed: boolean,
|
||||
pushEnabled: boolean,
|
||||
sealable: boolean,
|
||||
seal: Seal,
|
||||
seal: SealEntity,
|
||||
enableIce: boolean,
|
||||
multiFactorAuth: boolean,
|
||||
webPushKey: string,
|
||||
|
@ -6,6 +6,7 @@ import { getProfile } from './net/getProfile';
|
||||
import { getProfileImageUrl } from './net/getProfileImageUrl';
|
||||
import { setProfileData } from './net/setProfileData';
|
||||
import { setProfileImage } from './net/setProfileImage';
|
||||
import { getUsername } from './net/getUsername';
|
||||
import { ProfileEntity, defaultProfileEntity } from './entities';
|
||||
|
||||
const CLOSE_POLL_MS = 100;
|
||||
@ -63,6 +64,7 @@ export class IdentityModule implements Identity {
|
||||
const profile = await getProfile(node, secure, token);
|
||||
await this.store.setProfileData(guid, profile);
|
||||
await this.store.setProfileRevision(guid, nextRev);
|
||||
this.profile = profile;
|
||||
this.emitter.emit('profile', this.getProfile());
|
||||
this.revision = nextRev;
|
||||
if (this.nextRevision === nextRev) {
|
||||
@ -94,7 +96,7 @@ export class IdentityModule implements Identity {
|
||||
this.emitter.off('profile', ev);
|
||||
}
|
||||
|
||||
public async close(): void {
|
||||
public async close(): Promise<void> {
|
||||
this.closing = true;
|
||||
while(this.syncing) {
|
||||
await new Promise(r => setTimeout(r, CLOSE_POLL_MS));
|
||||
@ -107,16 +109,23 @@ export class IdentityModule implements Identity {
|
||||
}
|
||||
|
||||
public async setProfileData(name: string, location: string, description: string): Promise<void> {
|
||||
const { node, secure, token } = this;
|
||||
await setProfileData(node, secure, token, name, location, description);
|
||||
}
|
||||
|
||||
public async setProfileImage(image: string): Promise<void> {
|
||||
const { node, secure, token } = this;
|
||||
await setProfileImage(node, secure, token, image);
|
||||
}
|
||||
|
||||
public async getHandleStatus(handle: string): Promise<void> {
|
||||
public async getHandleStatus(handle: string): Promise<boolean> {
|
||||
const { node, secure, token } = this;
|
||||
return await getUsername(handle, token, node, secure);
|
||||
}
|
||||
|
||||
public getProfileImageUrl(): string {
|
||||
return getProfileImageUrl(this.node, this.secure, this.token, this.revision);
|
||||
const { node, secure, token, revision } = this;
|
||||
return getProfileImageUrl(node, secure, token, revision);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,7 @@ export class DatabagSDK {
|
||||
}
|
||||
|
||||
public async logout(session: Session, all: boolean): Promise<void> {
|
||||
const params = session.close();
|
||||
const params = await session.close();
|
||||
try {
|
||||
const { node, secure, token } = params;
|
||||
await clearLogin(node, secure, token, all);
|
||||
|
@ -133,7 +133,7 @@ export class SessionModule implements Session {
|
||||
}
|
||||
}
|
||||
|
||||
public async close(): { node: string, secure: boolean, token: string } {
|
||||
public async close(): Promise<{ node: string, secure: boolean, token: string }> {
|
||||
await this.content.close();
|
||||
await this.attribute.close();
|
||||
await this.alias.close();
|
||||
@ -142,7 +142,8 @@ export class SessionModule implements Session {
|
||||
await this.account.close();
|
||||
await this.stream.close();
|
||||
this.connection.close();
|
||||
return { node: this.node, secure: this.secure, token: this.token };
|
||||
const { node, secure, token } = this;
|
||||
return { node: node, secure: secure, token: token };
|
||||
}
|
||||
|
||||
public getAccount(): Account {
|
||||
|
@ -27,6 +27,6 @@ export class StreamModule implements Stream {
|
||||
this.emitter.off('channel', ev);
|
||||
}
|
||||
|
||||
public async close(): void {
|
||||
public async close(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user