mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-12-23 18:52:22 +00:00
Format with Prettier 2.3
Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
6658f0d5b4
commit
eaf1852fe5
9 changed files with 94 additions and 88 deletions
|
@ -33,9 +33,9 @@ export class TokensController {
|
|||
@Get()
|
||||
async getUserTokens(): Promise<AuthTokenDto[]> {
|
||||
// ToDo: Get real userName
|
||||
return (
|
||||
await this.authService.getTokensByUsername('hardcoded')
|
||||
).map((token) => this.authService.toAuthTokenDto(token));
|
||||
return (await this.authService.getTokensByUsername('hardcoded')).map(
|
||||
(token) => this.authService.toAuthTokenDto(token),
|
||||
);
|
||||
}
|
||||
|
||||
@Post()
|
||||
|
|
|
@ -159,13 +159,15 @@ describe('AuthService', () => {
|
|||
user: user,
|
||||
lastUsed: new Date(1549312452000),
|
||||
});
|
||||
jest.spyOn(authTokenRepo, 'save').mockImplementationOnce(
|
||||
async (authTokenSaved, _): Promise<AuthToken> => {
|
||||
expect(authTokenSaved.keyId).toEqual(authToken.keyId);
|
||||
expect(authTokenSaved.lastUsed).not.toEqual(1549312452000);
|
||||
return authToken;
|
||||
},
|
||||
);
|
||||
jest
|
||||
.spyOn(authTokenRepo, 'save')
|
||||
.mockImplementationOnce(
|
||||
async (authTokenSaved, _): Promise<AuthToken> => {
|
||||
expect(authTokenSaved.keyId).toEqual(authToken.keyId);
|
||||
expect(authTokenSaved.lastUsed).not.toEqual(1549312452000);
|
||||
return authToken;
|
||||
},
|
||||
);
|
||||
await service.setLastUsedToken(authToken.keyId);
|
||||
});
|
||||
it('throws if the token is not in the database', async () => {
|
||||
|
@ -189,11 +191,11 @@ describe('AuthService', () => {
|
|||
user: user,
|
||||
accessTokenHash: accessTokenHash,
|
||||
});
|
||||
jest.spyOn(authTokenRepo, 'save').mockImplementationOnce(
|
||||
async (_, __): Promise<AuthToken> => {
|
||||
jest
|
||||
.spyOn(authTokenRepo, 'save')
|
||||
.mockImplementationOnce(async (_, __): Promise<AuthToken> => {
|
||||
return authToken;
|
||||
},
|
||||
);
|
||||
});
|
||||
const userByToken = await service.validateToken(
|
||||
`${authToken.keyId}.${token}`,
|
||||
);
|
||||
|
@ -222,15 +224,15 @@ describe('AuthService', () => {
|
|||
...authToken,
|
||||
user: user,
|
||||
});
|
||||
jest.spyOn(authTokenRepo, 'remove').mockImplementationOnce(
|
||||
async (token, __): Promise<AuthToken> => {
|
||||
jest
|
||||
.spyOn(authTokenRepo, 'remove')
|
||||
.mockImplementationOnce(async (token, __): Promise<AuthToken> => {
|
||||
expect(token).toEqual({
|
||||
...authToken,
|
||||
user: user,
|
||||
});
|
||||
return authToken;
|
||||
},
|
||||
);
|
||||
});
|
||||
await service.removeToken(authToken.keyId);
|
||||
});
|
||||
it('throws if the token is not in the database', async () => {
|
||||
|
@ -249,12 +251,14 @@ describe('AuthService', () => {
|
|||
...user,
|
||||
authTokens: [authToken],
|
||||
});
|
||||
jest.spyOn(authTokenRepo, 'save').mockImplementationOnce(
|
||||
async (authTokenSaved: AuthToken, _): Promise<AuthToken> => {
|
||||
expect(authTokenSaved.lastUsed).toBeNull();
|
||||
return authTokenSaved;
|
||||
},
|
||||
);
|
||||
jest
|
||||
.spyOn(authTokenRepo, 'save')
|
||||
.mockImplementationOnce(
|
||||
async (authTokenSaved: AuthToken, _): Promise<AuthToken> => {
|
||||
expect(authTokenSaved.lastUsed).toBeNull();
|
||||
return authTokenSaved;
|
||||
},
|
||||
);
|
||||
const token = await service.createTokenForUser(
|
||||
user.userName,
|
||||
identifier,
|
||||
|
@ -273,12 +277,14 @@ describe('AuthService', () => {
|
|||
...user,
|
||||
authTokens: [authToken],
|
||||
});
|
||||
jest.spyOn(authTokenRepo, 'save').mockImplementationOnce(
|
||||
async (authTokenSaved: AuthToken, _): Promise<AuthToken> => {
|
||||
expect(authTokenSaved.lastUsed).toBeNull();
|
||||
return authTokenSaved;
|
||||
},
|
||||
);
|
||||
jest
|
||||
.spyOn(authTokenRepo, 'save')
|
||||
.mockImplementationOnce(
|
||||
async (authTokenSaved: AuthToken, _): Promise<AuthToken> => {
|
||||
expect(authTokenSaved.lastUsed).toBeNull();
|
||||
return authTokenSaved;
|
||||
},
|
||||
);
|
||||
const validUntil = new Date().getTime() + 30000;
|
||||
const token = await service.createTokenForUser(
|
||||
user.userName,
|
||||
|
|
|
@ -229,20 +229,18 @@ const authSchema = Joi.object({
|
|||
|
||||
export default registerAs('authConfig', () => {
|
||||
// ToDo: Validate these with Joi to prevent duplicate entries?
|
||||
const gitlabNames = toArrayConfig(
|
||||
process.env.HD_AUTH_GITLABS,
|
||||
',',
|
||||
).map((name) => name.toUpperCase());
|
||||
const gitlabNames = toArrayConfig(process.env.HD_AUTH_GITLABS, ',').map(
|
||||
(name) => name.toUpperCase(),
|
||||
);
|
||||
const ldapNames = toArrayConfig(process.env.HD_AUTH_LDAPS, ',').map((name) =>
|
||||
name.toUpperCase(),
|
||||
);
|
||||
const samlNames = toArrayConfig(process.env.HD_AUTH_SAMLS, ',').map((name) =>
|
||||
name.toUpperCase(),
|
||||
);
|
||||
const oauth2Names = toArrayConfig(
|
||||
process.env.HD_AUTH_OAUTH2S,
|
||||
',',
|
||||
).map((name) => name.toUpperCase());
|
||||
const oauth2Names = toArrayConfig(process.env.HD_AUTH_OAUTH2S, ',').map(
|
||||
(name) => name.toUpperCase(),
|
||||
);
|
||||
|
||||
const gitlabs = gitlabNames.map((gitlabName) => {
|
||||
return {
|
||||
|
|
|
@ -210,12 +210,13 @@ describe('FrontendConfigService', () => {
|
|||
imprint: imprintLink,
|
||||
},
|
||||
};
|
||||
const externalServicesConfig: ExternalServicesConfig = {
|
||||
plantUmlServer: plantUmlServer,
|
||||
imageProxy: imageProxy,
|
||||
};
|
||||
const module: TestingModule = await Test.createTestingModule(
|
||||
const externalServicesConfig: ExternalServicesConfig =
|
||||
{
|
||||
plantUmlServer: plantUmlServer,
|
||||
imageProxy: imageProxy,
|
||||
};
|
||||
const module: TestingModule =
|
||||
await Test.createTestingModule({
|
||||
imports: [
|
||||
ConfigModule.forRoot({
|
||||
isGlobal: true,
|
||||
|
@ -238,8 +239,7 @@ describe('FrontendConfigService', () => {
|
|||
LoggerModule,
|
||||
],
|
||||
providers: [FrontendConfigService],
|
||||
},
|
||||
).compile();
|
||||
}).compile();
|
||||
|
||||
const service = module.get(FrontendConfigService);
|
||||
const config = await service.getFrontendConfig();
|
||||
|
|
|
@ -250,12 +250,14 @@ describe('HistoryService', () => {
|
|||
const historyEntry = HistoryEntry.create(user, note);
|
||||
it('with an entry', async () => {
|
||||
jest.spyOn(historyRepo, 'find').mockResolvedValueOnce([historyEntry]);
|
||||
jest.spyOn(historyRepo, 'remove').mockImplementationOnce(
|
||||
async (entry: HistoryEntry): Promise<HistoryEntry> => {
|
||||
expect(entry).toEqual(historyEntry);
|
||||
return entry;
|
||||
},
|
||||
);
|
||||
jest
|
||||
.spyOn(historyRepo, 'remove')
|
||||
.mockImplementationOnce(
|
||||
async (entry: HistoryEntry): Promise<HistoryEntry> => {
|
||||
expect(entry).toEqual(historyEntry);
|
||||
return entry;
|
||||
},
|
||||
);
|
||||
await service.deleteHistory(user);
|
||||
});
|
||||
it('with multiple entries', async () => {
|
||||
|
@ -298,12 +300,14 @@ describe('HistoryService', () => {
|
|||
const historyEntry = HistoryEntry.create(user, note);
|
||||
jest.spyOn(historyRepo, 'findOne').mockResolvedValueOnce(historyEntry);
|
||||
jest.spyOn(noteRepo, 'findOne').mockResolvedValueOnce(note);
|
||||
jest.spyOn(historyRepo, 'remove').mockImplementation(
|
||||
async (entry: HistoryEntry): Promise<HistoryEntry> => {
|
||||
expect(entry).toEqual(historyEntry);
|
||||
return entry;
|
||||
},
|
||||
);
|
||||
jest
|
||||
.spyOn(historyRepo, 'remove')
|
||||
.mockImplementation(
|
||||
async (entry: HistoryEntry): Promise<HistoryEntry> => {
|
||||
expect(entry).toEqual(historyEntry);
|
||||
return entry;
|
||||
},
|
||||
);
|
||||
await service.deleteHistoryEntry(alias, user);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -42,9 +42,8 @@ export class AzureBackend implements MediaBackend {
|
|||
buffer: Buffer,
|
||||
fileName: string,
|
||||
): Promise<[string, BackendData]> {
|
||||
const blockBlobClient: BlockBlobClient = this.client.getBlockBlobClient(
|
||||
fileName,
|
||||
);
|
||||
const blockBlobClient: BlockBlobClient =
|
||||
this.client.getBlockBlobClient(fileName);
|
||||
try {
|
||||
await blockBlobClient.upload(buffer, buffer.length);
|
||||
const url = this.getUrl(fileName);
|
||||
|
@ -61,9 +60,8 @@ export class AzureBackend implements MediaBackend {
|
|||
}
|
||||
|
||||
async deleteFile(fileName: string, _: BackendData): Promise<void> {
|
||||
const blockBlobClient: BlockBlobClient = this.client.getBlockBlobClient(
|
||||
fileName,
|
||||
);
|
||||
const blockBlobClient: BlockBlobClient =
|
||||
this.client.getBlockBlobClient(fileName);
|
||||
try {
|
||||
await blockBlobClient.delete();
|
||||
const url = this.getUrl(fileName);
|
||||
|
|
|
@ -112,15 +112,17 @@ describe('MediaService', () => {
|
|||
fileId = entry.id;
|
||||
return entry;
|
||||
});
|
||||
jest.spyOn(service.mediaBackend, 'saveFile').mockImplementationOnce(
|
||||
async (
|
||||
buffer: Buffer,
|
||||
fileName: string,
|
||||
): Promise<[string, BackendData]> => {
|
||||
expect(buffer).toEqual(testImage);
|
||||
return [fileName, null];
|
||||
},
|
||||
);
|
||||
jest
|
||||
.spyOn(service.mediaBackend, 'saveFile')
|
||||
.mockImplementationOnce(
|
||||
async (
|
||||
buffer: Buffer,
|
||||
fileName: string,
|
||||
): Promise<[string, BackendData]> => {
|
||||
expect(buffer).toEqual(testImage);
|
||||
return [fileName, null];
|
||||
},
|
||||
);
|
||||
const url = await service.saveFile(testImage, 'hardcoded', 'test');
|
||||
expect(url).toEqual(fileId);
|
||||
});
|
||||
|
@ -150,12 +152,14 @@ describe('MediaService', () => {
|
|||
userName: 'hardcoded',
|
||||
} as User,
|
||||
} as MediaUpload;
|
||||
jest.spyOn(service.mediaBackend, 'deleteFile').mockImplementationOnce(
|
||||
async (fileName: string, backendData: BackendData): Promise<void> => {
|
||||
expect(fileName).toEqual(mockMediaUploadEntry.id);
|
||||
expect(backendData).toEqual(mockMediaUploadEntry.backendData);
|
||||
},
|
||||
);
|
||||
jest
|
||||
.spyOn(service.mediaBackend, 'deleteFile')
|
||||
.mockImplementationOnce(
|
||||
async (fileName: string, backendData: BackendData): Promise<void> => {
|
||||
expect(fileName).toEqual(mockMediaUploadEntry.id);
|
||||
expect(backendData).toEqual(mockMediaUploadEntry.backendData);
|
||||
},
|
||||
);
|
||||
jest
|
||||
.spyOn(mediaRepo, 'remove')
|
||||
.mockImplementationOnce(async (entry, _) => {
|
||||
|
|
|
@ -462,9 +462,8 @@ describe('PermissionsService', () => {
|
|||
|
||||
describe('check if groups work with', () => {
|
||||
const guestPermission = GuestPermission.WRITE;
|
||||
const rawPermissions = createNoteGroupPermissionsCombinations(
|
||||
guestPermission,
|
||||
);
|
||||
const rawPermissions =
|
||||
createNoteGroupPermissionsCombinations(guestPermission);
|
||||
const permissions = permuteNoteGroupPermissions(rawPermissions);
|
||||
let i = 0;
|
||||
for (const permission of permissions) {
|
||||
|
|
|
@ -122,18 +122,15 @@ describe('Me', () => {
|
|||
it('works with an existing note', async () => {
|
||||
const noteName = 'testGetNoteHistory2';
|
||||
const note = await notesService.createNote('', noteName);
|
||||
const createdHistoryEntry = await historyService.createOrUpdateHistoryEntry(
|
||||
note,
|
||||
user,
|
||||
);
|
||||
const createdHistoryEntry =
|
||||
await historyService.createOrUpdateHistoryEntry(note, user);
|
||||
const response = await request(app.getHttpServer())
|
||||
.get(`/me/history/${noteName}`)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200);
|
||||
const historyEntry = <HistoryEntryDto>response.body;
|
||||
const historyEntryDto = historyService.toHistoryEntryDto(
|
||||
createdHistoryEntry,
|
||||
);
|
||||
const historyEntryDto =
|
||||
historyService.toHistoryEntryDto(createdHistoryEntry);
|
||||
expect(historyEntry.identifier).toEqual(historyEntryDto.identifier);
|
||||
expect(historyEntry.title).toEqual(historyEntryDto.title);
|
||||
expect(historyEntry.tags).toEqual(historyEntryDto.tags);
|
||||
|
|
Loading…
Reference in a new issue