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 800f5a4dc3
commit e4317725cd
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,13 +159,15 @@ describe('AuthService', () => {
user: user, user: user,
lastUsed: new Date(1549312452000), lastUsed: new Date(1549312452000),
}); });
jest.spyOn(authTokenRepo, 'save').mockImplementationOnce( jest
async (authTokenSaved, _): Promise<AuthToken> => { .spyOn(authTokenRepo, 'save')
expect(authTokenSaved.keyId).toEqual(authToken.keyId); .mockImplementationOnce(
expect(authTokenSaved.lastUsed).not.toEqual(1549312452000); async (authTokenSaved, _): Promise<AuthToken> => {
return authToken; expect(authTokenSaved.keyId).toEqual(authToken.keyId);
}, expect(authTokenSaved.lastUsed).not.toEqual(1549312452000);
); return authToken;
},
);
await service.setLastUsedToken(authToken.keyId); await service.setLastUsedToken(authToken.keyId);
}); });
it('throws if the token is not in the database', async () => { it('throws if the token is not in the database', async () => {
@ -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,12 +251,14 @@ describe('AuthService', () => {
...user, ...user,
authTokens: [authToken], authTokens: [authToken],
}); });
jest.spyOn(authTokenRepo, 'save').mockImplementationOnce( jest
async (authTokenSaved: AuthToken, _): Promise<AuthToken> => { .spyOn(authTokenRepo, 'save')
expect(authTokenSaved.lastUsed).toBeNull(); .mockImplementationOnce(
return authTokenSaved; async (authTokenSaved: AuthToken, _): Promise<AuthToken> => {
}, expect(authTokenSaved.lastUsed).toBeNull();
); return authTokenSaved;
},
);
const token = await service.createTokenForUser( const token = await service.createTokenForUser(
user.userName, user.userName,
identifier, identifier,
@ -273,12 +277,14 @@ describe('AuthService', () => {
...user, ...user,
authTokens: [authToken], authTokens: [authToken],
}); });
jest.spyOn(authTokenRepo, 'save').mockImplementationOnce( jest
async (authTokenSaved: AuthToken, _): Promise<AuthToken> => { .spyOn(authTokenRepo, 'save')
expect(authTokenSaved.lastUsed).toBeNull(); .mockImplementationOnce(
return authTokenSaved; async (authTokenSaved: AuthToken, _): Promise<AuthToken> => {
}, expect(authTokenSaved.lastUsed).toBeNull();
); return authTokenSaved;
},
);
const validUntil = new Date().getTime() + 30000; const validUntil = new Date().getTime() + 30000;
const token = await service.createTokenForUser( const token = await service.createTokenForUser(
user.userName, user.userName,

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,
imageProxy: imageProxy,
};
const module: TestingModule = await Test.createTestingModule(
{ {
plantUmlServer: plantUmlServer,
imageProxy: imageProxy,
};
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,12 +250,14 @@ 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
async (entry: HistoryEntry): Promise<HistoryEntry> => { .spyOn(historyRepo, 'remove')
expect(entry).toEqual(historyEntry); .mockImplementationOnce(
return entry; async (entry: HistoryEntry): Promise<HistoryEntry> => {
}, expect(entry).toEqual(historyEntry);
); return entry;
},
);
await service.deleteHistory(user); await service.deleteHistory(user);
}); });
it('with multiple entries', async () => { it('with multiple entries', async () => {
@ -298,12 +300,14 @@ 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
async (entry: HistoryEntry): Promise<HistoryEntry> => { .spyOn(historyRepo, 'remove')
expect(entry).toEqual(historyEntry); .mockImplementation(
return entry; async (entry: HistoryEntry): Promise<HistoryEntry> => {
}, expect(entry).toEqual(historyEntry);
); return entry;
},
);
await service.deleteHistoryEntry(alias, user); await service.deleteHistoryEntry(alias, user);
}); });
}); });

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,15 +112,17 @@ describe('MediaService', () => {
fileId = entry.id; fileId = entry.id;
return entry; return entry;
}); });
jest.spyOn(service.mediaBackend, 'saveFile').mockImplementationOnce( jest
async ( .spyOn(service.mediaBackend, 'saveFile')
buffer: Buffer, .mockImplementationOnce(
fileName: string, async (
): Promise<[string, BackendData]> => { buffer: Buffer,
expect(buffer).toEqual(testImage); fileName: string,
return [fileName, null]; ): Promise<[string, BackendData]> => {
}, expect(buffer).toEqual(testImage);
); return [fileName, null];
},
);
const url = await service.saveFile(testImage, 'hardcoded', 'test'); const url = await service.saveFile(testImage, 'hardcoded', 'test');
expect(url).toEqual(fileId); expect(url).toEqual(fileId);
}); });
@ -150,12 +152,14 @@ describe('MediaService', () => {
userName: 'hardcoded', userName: 'hardcoded',
} as User, } as User,
} as MediaUpload; } as MediaUpload;
jest.spyOn(service.mediaBackend, 'deleteFile').mockImplementationOnce( jest
async (fileName: string, backendData: BackendData): Promise<void> => { .spyOn(service.mediaBackend, 'deleteFile')
expect(fileName).toEqual(mockMediaUploadEntry.id); .mockImplementationOnce(
expect(backendData).toEqual(mockMediaUploadEntry.backendData); async (fileName: string, backendData: BackendData): Promise<void> => {
}, expect(fileName).toEqual(mockMediaUploadEntry.id);
); expect(backendData).toEqual(mockMediaUploadEntry.backendData);
},
);
jest jest
.spyOn(mediaRepo, 'remove') .spyOn(mediaRepo, 'remove')
.mockImplementationOnce(async (entry, _) => { .mockImplementationOnce(async (entry, _) => {

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);