Format with Prettier 2.3

Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
David Mehren 2021-05-15 21:13:44 +02:00
parent 6658f0d5b4
commit eaf1852fe5
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3
9 changed files with 94 additions and 88 deletions

View file

@ -33,9 +33,9 @@ export class TokensController {
@Get() @Get()
async getUserTokens(): Promise<AuthTokenDto[]> { async getUserTokens(): Promise<AuthTokenDto[]> {
// ToDo: Get real userName // ToDo: Get real userName
return ( return (await this.authService.getTokensByUsername('hardcoded')).map(
await this.authService.getTokensByUsername('hardcoded') (token) => this.authService.toAuthTokenDto(token),
).map((token) => this.authService.toAuthTokenDto(token)); );
} }
@Post() @Post()

View file

@ -159,7 +159,9 @@ describe('AuthService', () => {
user: user, user: user,
lastUsed: new Date(1549312452000), lastUsed: new Date(1549312452000),
}); });
jest.spyOn(authTokenRepo, 'save').mockImplementationOnce( jest
.spyOn(authTokenRepo, 'save')
.mockImplementationOnce(
async (authTokenSaved, _): Promise<AuthToken> => { async (authTokenSaved, _): Promise<AuthToken> => {
expect(authTokenSaved.keyId).toEqual(authToken.keyId); expect(authTokenSaved.keyId).toEqual(authToken.keyId);
expect(authTokenSaved.lastUsed).not.toEqual(1549312452000); expect(authTokenSaved.lastUsed).not.toEqual(1549312452000);
@ -189,11 +191,11 @@ describe('AuthService', () => {
user: user, user: user,
accessTokenHash: accessTokenHash, accessTokenHash: accessTokenHash,
}); });
jest.spyOn(authTokenRepo, 'save').mockImplementationOnce( jest
async (_, __): Promise<AuthToken> => { .spyOn(authTokenRepo, 'save')
.mockImplementationOnce(async (_, __): Promise<AuthToken> => {
return authToken; return authToken;
}, });
);
const userByToken = await service.validateToken( const userByToken = await service.validateToken(
`${authToken.keyId}.${token}`, `${authToken.keyId}.${token}`,
); );
@ -222,15 +224,15 @@ describe('AuthService', () => {
...authToken, ...authToken,
user: user, user: user,
}); });
jest.spyOn(authTokenRepo, 'remove').mockImplementationOnce( jest
async (token, __): Promise<AuthToken> => { .spyOn(authTokenRepo, 'remove')
.mockImplementationOnce(async (token, __): Promise<AuthToken> => {
expect(token).toEqual({ expect(token).toEqual({
...authToken, ...authToken,
user: user, user: user,
}); });
return authToken; return authToken;
}, });
);
await service.removeToken(authToken.keyId); await service.removeToken(authToken.keyId);
}); });
it('throws if the token is not in the database', async () => { it('throws if the token is not in the database', async () => {
@ -249,7 +251,9 @@ describe('AuthService', () => {
...user, ...user,
authTokens: [authToken], authTokens: [authToken],
}); });
jest.spyOn(authTokenRepo, 'save').mockImplementationOnce( jest
.spyOn(authTokenRepo, 'save')
.mockImplementationOnce(
async (authTokenSaved: AuthToken, _): Promise<AuthToken> => { async (authTokenSaved: AuthToken, _): Promise<AuthToken> => {
expect(authTokenSaved.lastUsed).toBeNull(); expect(authTokenSaved.lastUsed).toBeNull();
return authTokenSaved; return authTokenSaved;
@ -273,7 +277,9 @@ describe('AuthService', () => {
...user, ...user,
authTokens: [authToken], authTokens: [authToken],
}); });
jest.spyOn(authTokenRepo, 'save').mockImplementationOnce( jest
.spyOn(authTokenRepo, 'save')
.mockImplementationOnce(
async (authTokenSaved: AuthToken, _): Promise<AuthToken> => { async (authTokenSaved: AuthToken, _): Promise<AuthToken> => {
expect(authTokenSaved.lastUsed).toBeNull(); expect(authTokenSaved.lastUsed).toBeNull();
return authTokenSaved; return authTokenSaved;

View file

@ -229,20 +229,18 @@ const authSchema = Joi.object({
export default registerAs('authConfig', () => { export default registerAs('authConfig', () => {
// ToDo: Validate these with Joi to prevent duplicate entries? // ToDo: Validate these with Joi to prevent duplicate entries?
const gitlabNames = toArrayConfig( const gitlabNames = toArrayConfig(process.env.HD_AUTH_GITLABS, ',').map(
process.env.HD_AUTH_GITLABS, (name) => name.toUpperCase(),
',', );
).map((name) => name.toUpperCase());
const ldapNames = toArrayConfig(process.env.HD_AUTH_LDAPS, ',').map((name) => const ldapNames = toArrayConfig(process.env.HD_AUTH_LDAPS, ',').map((name) =>
name.toUpperCase(), name.toUpperCase(),
); );
const samlNames = toArrayConfig(process.env.HD_AUTH_SAMLS, ',').map((name) => const samlNames = toArrayConfig(process.env.HD_AUTH_SAMLS, ',').map((name) =>
name.toUpperCase(), name.toUpperCase(),
); );
const oauth2Names = toArrayConfig( const oauth2Names = toArrayConfig(process.env.HD_AUTH_OAUTH2S, ',').map(
process.env.HD_AUTH_OAUTH2S, (name) => name.toUpperCase(),
',', );
).map((name) => name.toUpperCase());
const gitlabs = gitlabNames.map((gitlabName) => { const gitlabs = gitlabNames.map((gitlabName) => {
return { return {

View file

@ -210,12 +210,13 @@ describe('FrontendConfigService', () => {
imprint: imprintLink, imprint: imprintLink,
}, },
}; };
const externalServicesConfig: ExternalServicesConfig = { const externalServicesConfig: ExternalServicesConfig =
{
plantUmlServer: plantUmlServer, plantUmlServer: plantUmlServer,
imageProxy: imageProxy, imageProxy: imageProxy,
}; };
const module: TestingModule = await Test.createTestingModule( const module: TestingModule =
{ await Test.createTestingModule({
imports: [ imports: [
ConfigModule.forRoot({ ConfigModule.forRoot({
isGlobal: true, isGlobal: true,
@ -238,8 +239,7 @@ describe('FrontendConfigService', () => {
LoggerModule, LoggerModule,
], ],
providers: [FrontendConfigService], providers: [FrontendConfigService],
}, }).compile();
).compile();
const service = module.get(FrontendConfigService); const service = module.get(FrontendConfigService);
const config = await service.getFrontendConfig(); const config = await service.getFrontendConfig();

View file

@ -250,7 +250,9 @@ describe('HistoryService', () => {
const historyEntry = HistoryEntry.create(user, note); const historyEntry = HistoryEntry.create(user, note);
it('with an entry', async () => { it('with an entry', async () => {
jest.spyOn(historyRepo, 'find').mockResolvedValueOnce([historyEntry]); jest.spyOn(historyRepo, 'find').mockResolvedValueOnce([historyEntry]);
jest.spyOn(historyRepo, 'remove').mockImplementationOnce( jest
.spyOn(historyRepo, 'remove')
.mockImplementationOnce(
async (entry: HistoryEntry): Promise<HistoryEntry> => { async (entry: HistoryEntry): Promise<HistoryEntry> => {
expect(entry).toEqual(historyEntry); expect(entry).toEqual(historyEntry);
return entry; return entry;
@ -298,7 +300,9 @@ describe('HistoryService', () => {
const historyEntry = HistoryEntry.create(user, note); const historyEntry = HistoryEntry.create(user, note);
jest.spyOn(historyRepo, 'findOne').mockResolvedValueOnce(historyEntry); jest.spyOn(historyRepo, 'findOne').mockResolvedValueOnce(historyEntry);
jest.spyOn(noteRepo, 'findOne').mockResolvedValueOnce(note); jest.spyOn(noteRepo, 'findOne').mockResolvedValueOnce(note);
jest.spyOn(historyRepo, 'remove').mockImplementation( jest
.spyOn(historyRepo, 'remove')
.mockImplementation(
async (entry: HistoryEntry): Promise<HistoryEntry> => { async (entry: HistoryEntry): Promise<HistoryEntry> => {
expect(entry).toEqual(historyEntry); expect(entry).toEqual(historyEntry);
return entry; return entry;

View file

@ -42,9 +42,8 @@ export class AzureBackend implements MediaBackend {
buffer: Buffer, buffer: Buffer,
fileName: string, fileName: string,
): Promise<[string, BackendData]> { ): Promise<[string, BackendData]> {
const blockBlobClient: BlockBlobClient = this.client.getBlockBlobClient( const blockBlobClient: BlockBlobClient =
fileName, this.client.getBlockBlobClient(fileName);
);
try { try {
await blockBlobClient.upload(buffer, buffer.length); await blockBlobClient.upload(buffer, buffer.length);
const url = this.getUrl(fileName); const url = this.getUrl(fileName);
@ -61,9 +60,8 @@ export class AzureBackend implements MediaBackend {
} }
async deleteFile(fileName: string, _: BackendData): Promise<void> { async deleteFile(fileName: string, _: BackendData): Promise<void> {
const blockBlobClient: BlockBlobClient = this.client.getBlockBlobClient( const blockBlobClient: BlockBlobClient =
fileName, this.client.getBlockBlobClient(fileName);
);
try { try {
await blockBlobClient.delete(); await blockBlobClient.delete();
const url = this.getUrl(fileName); const url = this.getUrl(fileName);

View file

@ -112,7 +112,9 @@ describe('MediaService', () => {
fileId = entry.id; fileId = entry.id;
return entry; return entry;
}); });
jest.spyOn(service.mediaBackend, 'saveFile').mockImplementationOnce( jest
.spyOn(service.mediaBackend, 'saveFile')
.mockImplementationOnce(
async ( async (
buffer: Buffer, buffer: Buffer,
fileName: string, fileName: string,
@ -150,7 +152,9 @@ describe('MediaService', () => {
userName: 'hardcoded', userName: 'hardcoded',
} as User, } as User,
} as MediaUpload; } as MediaUpload;
jest.spyOn(service.mediaBackend, 'deleteFile').mockImplementationOnce( jest
.spyOn(service.mediaBackend, 'deleteFile')
.mockImplementationOnce(
async (fileName: string, backendData: BackendData): Promise<void> => { async (fileName: string, backendData: BackendData): Promise<void> => {
expect(fileName).toEqual(mockMediaUploadEntry.id); expect(fileName).toEqual(mockMediaUploadEntry.id);
expect(backendData).toEqual(mockMediaUploadEntry.backendData); expect(backendData).toEqual(mockMediaUploadEntry.backendData);

View file

@ -462,9 +462,8 @@ describe('PermissionsService', () => {
describe('check if groups work with', () => { describe('check if groups work with', () => {
const guestPermission = GuestPermission.WRITE; const guestPermission = GuestPermission.WRITE;
const rawPermissions = createNoteGroupPermissionsCombinations( const rawPermissions =
guestPermission, createNoteGroupPermissionsCombinations(guestPermission);
);
const permissions = permuteNoteGroupPermissions(rawPermissions); const permissions = permuteNoteGroupPermissions(rawPermissions);
let i = 0; let i = 0;
for (const permission of permissions) { for (const permission of permissions) {

View file

@ -122,18 +122,15 @@ describe('Me', () => {
it('works with an existing note', async () => { it('works with an existing note', async () => {
const noteName = 'testGetNoteHistory2'; const noteName = 'testGetNoteHistory2';
const note = await notesService.createNote('', noteName); const note = await notesService.createNote('', noteName);
const createdHistoryEntry = await historyService.createOrUpdateHistoryEntry( const createdHistoryEntry =
note, await historyService.createOrUpdateHistoryEntry(note, user);
user,
);
const response = await request(app.getHttpServer()) const response = await request(app.getHttpServer())
.get(`/me/history/${noteName}`) .get(`/me/history/${noteName}`)
.expect('Content-Type', /json/) .expect('Content-Type', /json/)
.expect(200); .expect(200);
const historyEntry = <HistoryEntryDto>response.body; const historyEntry = <HistoryEntryDto>response.body;
const historyEntryDto = historyService.toHistoryEntryDto( const historyEntryDto =
createdHistoryEntry, historyService.toHistoryEntryDto(createdHistoryEntry);
);
expect(historyEntry.identifier).toEqual(historyEntryDto.identifier); expect(historyEntry.identifier).toEqual(historyEntryDto.identifier);
expect(historyEntry.title).toEqual(historyEntryDto.title); expect(historyEntry.title).toEqual(historyEntryDto.title);
expect(historyEntry.tags).toEqual(historyEntryDto.tags); expect(historyEntry.tags).toEqual(historyEntryDto.tags);