1
0
mirror of https://github.com/bitwarden/jslib synced 2025-12-23 19:53:55 +00:00

Apply prettier

This commit is contained in:
Hinton
2022-01-03 12:49:00 +01:00
parent d68d4b4bdc
commit c3aaf33ce1
586 changed files with 48808 additions and 43106 deletions

View File

@@ -1,123 +1,135 @@
import { Substitute, SubstituteOf } from '@fluffy-spoon/substitute';
import { Substitute, SubstituteOf } from "@fluffy-spoon/substitute";
import { ApiService } from 'src/abstractions/api.service';
import { CipherService } from 'src/abstractions/cipher.service';
import { CryptoService } from 'src/abstractions/crypto.service';
import { FolderService } from 'src/abstractions/folder.service';
import { ApiService } from "src/abstractions/api.service";
import { CipherService } from "src/abstractions/cipher.service";
import { CryptoService } from "src/abstractions/crypto.service";
import { FolderService } from "src/abstractions/folder.service";
import { ExportService } from 'src/services/export.service';
import { ExportService } from "src/services/export.service";
import { Cipher } from 'src/models/domain/cipher';
import { EncString } from 'src/models/domain/encString';
import { Login } from 'src/models/domain/login';
import { CipherWithIds as CipherExport } from 'src/models/export/cipherWithIds';
import { Cipher } from "src/models/domain/cipher";
import { EncString } from "src/models/domain/encString";
import { Login } from "src/models/domain/login";
import { CipherWithIds as CipherExport } from "src/models/export/cipherWithIds";
import { CipherType } from 'src/enums/cipherType';
import { CipherView } from 'src/models/view/cipherView';
import { LoginView } from 'src/models/view/loginView';
import { CipherType } from "src/enums/cipherType";
import { CipherView } from "src/models/view/cipherView";
import { LoginView } from "src/models/view/loginView";
import { BuildTestObject, GetUniqueString } from '../utils';
import { BuildTestObject, GetUniqueString } from "../utils";
const UserCipherViews = [
generateCipherView(false),
generateCipherView(false),
generateCipherView(true),
generateCipherView(false),
generateCipherView(false),
generateCipherView(true),
];
const UserCipherDomains = [
generateCipherDomain(false),
generateCipherDomain(false),
generateCipherDomain(true),
generateCipherDomain(false),
generateCipherDomain(false),
generateCipherDomain(true),
];
function generateCipherView(deleted: boolean) {
return BuildTestObject({
id: GetUniqueString('id'),
notes: GetUniqueString('notes'),
type: CipherType.Login,
login: BuildTestObject<LoginView>({
username: GetUniqueString('username'),
password: GetUniqueString('password'),
}, LoginView),
collectionIds: null,
deletedDate: deleted ? new Date() : null,
}, CipherView);
return BuildTestObject(
{
id: GetUniqueString("id"),
notes: GetUniqueString("notes"),
type: CipherType.Login,
login: BuildTestObject<LoginView>(
{
username: GetUniqueString("username"),
password: GetUniqueString("password"),
},
LoginView
),
collectionIds: null,
deletedDate: deleted ? new Date() : null,
},
CipherView
);
}
function generateCipherDomain(deleted: boolean) {
return BuildTestObject({
id: GetUniqueString('id'),
notes: new EncString(GetUniqueString('notes')),
type: CipherType.Login,
login: BuildTestObject<Login>({
username: new EncString(GetUniqueString('username')),
password: new EncString(GetUniqueString('password')),
}, Login),
collectionIds: null,
deletedDate: deleted ? new Date() : null,
}, Cipher);
return BuildTestObject(
{
id: GetUniqueString("id"),
notes: new EncString(GetUniqueString("notes")),
type: CipherType.Login,
login: BuildTestObject<Login>(
{
username: new EncString(GetUniqueString("username")),
password: new EncString(GetUniqueString("password")),
},
Login
),
collectionIds: null,
deletedDate: deleted ? new Date() : null,
},
Cipher
);
}
function expectEqualCiphers(ciphers: CipherView[] | Cipher[], jsonResult: string) {
const actual = JSON.stringify(JSON.parse(jsonResult).items);
const items: CipherExport[] = [];
ciphers.forEach((c: CipherView | Cipher) => {
const item = new CipherExport();
item.build(c);
items.push(item);
});
const actual = JSON.stringify(JSON.parse(jsonResult).items);
const items: CipherExport[] = [];
ciphers.forEach((c: CipherView | Cipher) => {
const item = new CipherExport();
item.build(c);
items.push(item);
});
expect(actual).toEqual(JSON.stringify(items));
expect(actual).toEqual(JSON.stringify(items));
}
describe('ExportService', () => {
let exportService: ExportService;
let apiService: SubstituteOf<ApiService>;
let cipherService: SubstituteOf<CipherService>;
let folderService: SubstituteOf<FolderService>;
let cryptoService: SubstituteOf<CryptoService>;
describe("ExportService", () => {
let exportService: ExportService;
let apiService: SubstituteOf<ApiService>;
let cipherService: SubstituteOf<CipherService>;
let folderService: SubstituteOf<FolderService>;
let cryptoService: SubstituteOf<CryptoService>;
beforeEach(() => {
apiService = Substitute.for<ApiService>();
cipherService = Substitute.for<CipherService>();
folderService = Substitute.for<FolderService>();
cryptoService = Substitute.for<CryptoService>();
beforeEach(() => {
apiService = Substitute.for<ApiService>();
cipherService = Substitute.for<CipherService>();
folderService = Substitute.for<FolderService>();
cryptoService = Substitute.for<CryptoService>();
folderService.getAllDecrypted().resolves([]);
folderService.getAll().resolves([]);
folderService.getAllDecrypted().resolves([]);
folderService.getAll().resolves([]);
exportService = new ExportService(folderService, cipherService, apiService, cryptoService);
});
exportService = new ExportService(folderService, cipherService, apiService, cryptoService);
});
it('exports unecrypted user ciphers', async () => {
cipherService.getAllDecrypted().resolves(UserCipherViews.slice(0, 1));
it("exports unecrypted user ciphers", async () => {
cipherService.getAllDecrypted().resolves(UserCipherViews.slice(0, 1));
const actual = await exportService.getExport('json');
const actual = await exportService.getExport("json");
expectEqualCiphers(UserCipherViews.slice(0, 1), actual);
});
expectEqualCiphers(UserCipherViews.slice(0, 1), actual);
});
it('exports encrypted json user ciphers', async () => {
cipherService.getAll().resolves(UserCipherDomains.slice(0, 1));
it("exports encrypted json user ciphers", async () => {
cipherService.getAll().resolves(UserCipherDomains.slice(0, 1));
const actual = await exportService.getExport('encrypted_json');
const actual = await exportService.getExport("encrypted_json");
expectEqualCiphers(UserCipherDomains.slice(0, 1), actual);
});
expectEqualCiphers(UserCipherDomains.slice(0, 1), actual);
});
it('does not unecrypted export trashed user items', async () => {
cipherService.getAllDecrypted().resolves(UserCipherViews);
it("does not unecrypted export trashed user items", async () => {
cipherService.getAllDecrypted().resolves(UserCipherViews);
const actual = await exportService.getExport('json');
const actual = await exportService.getExport("json");
expectEqualCiphers(UserCipherViews.slice(0, 2), actual);
});
expectEqualCiphers(UserCipherViews.slice(0, 2), actual);
});
it('does not encrypted export trashed user items', async () => {
cipherService.getAll().resolves(UserCipherDomains);
it("does not encrypted export trashed user items", async () => {
cipherService.getAll().resolves(UserCipherDomains);
const actual = await exportService.getExport('encrypted_json');
const actual = await exportService.getExport("encrypted_json");
expectEqualCiphers(UserCipherDomains.slice(0, 2), actual);
});
expectEqualCiphers(UserCipherDomains.slice(0, 2), actual);
});
});