mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-25 11:16:31 -05:00
Merge pull request #1986 from hedgedoc/fix/consistent_timestamps
This commit is contained in:
commit
9b856bf517
13 changed files with 36 additions and 36 deletions
|
@ -16,5 +16,5 @@ export class AuthTokenDto {
|
|||
validUntil: Date;
|
||||
@IsDate()
|
||||
@IsOptional()
|
||||
lastUsed: Date | null;
|
||||
lastUsedAt: Date | null;
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ export class AuthToken {
|
|||
nullable: true,
|
||||
type: 'date',
|
||||
})
|
||||
lastUsed: Date | null;
|
||||
lastUsedAt: Date | null;
|
||||
|
||||
public static create(
|
||||
keyId: string,
|
||||
|
@ -57,7 +57,7 @@ export class AuthToken {
|
|||
newToken.label = label;
|
||||
newToken.accessTokenHash = accessToken;
|
||||
newToken.validUntil = validUntil;
|
||||
newToken.lastUsed = null;
|
||||
newToken.lastUsedAt = null;
|
||||
return newToken;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -143,14 +143,14 @@ describe('AuthService', () => {
|
|||
jest.spyOn(authTokenRepo, 'findOne').mockResolvedValueOnce({
|
||||
...authToken,
|
||||
user: Promise.resolve(user),
|
||||
lastUsed: new Date(1549312452000),
|
||||
lastUsedAt: new Date(1549312452000),
|
||||
});
|
||||
jest
|
||||
.spyOn(authTokenRepo, 'save')
|
||||
.mockImplementationOnce(
|
||||
async (authTokenSaved, _): Promise<AuthToken> => {
|
||||
expect(authTokenSaved.keyId).toEqual(authToken.keyId);
|
||||
expect(authTokenSaved.lastUsed).not.toEqual(1549312452000);
|
||||
expect(authTokenSaved.lastUsedAt).not.toEqual(1549312452000);
|
||||
return authToken;
|
||||
},
|
||||
);
|
||||
|
@ -242,7 +242,7 @@ describe('AuthService', () => {
|
|||
.spyOn(authTokenRepo, 'save')
|
||||
.mockImplementationOnce(
|
||||
async (authTokenSaved: AuthToken, _): Promise<AuthToken> => {
|
||||
expect(authTokenSaved.lastUsed).toBeNull();
|
||||
expect(authTokenSaved.lastUsedAt).toBeNull();
|
||||
return authTokenSaved;
|
||||
},
|
||||
);
|
||||
|
@ -252,7 +252,7 @@ describe('AuthService', () => {
|
|||
token.validUntil.getTime() -
|
||||
(new Date().getTime() + 2 * 365 * 24 * 60 * 60 * 1000),
|
||||
).toBeLessThanOrEqual(10000);
|
||||
expect(token.lastUsed).toBeNull();
|
||||
expect(token.lastUsedAt).toBeNull();
|
||||
expect(token.secret.startsWith(token.keyId)).toBeTruthy();
|
||||
});
|
||||
it('with validUntil not 0', async () => {
|
||||
|
@ -261,7 +261,7 @@ describe('AuthService', () => {
|
|||
.spyOn(authTokenRepo, 'save')
|
||||
.mockImplementationOnce(
|
||||
async (authTokenSaved: AuthToken, _): Promise<AuthToken> => {
|
||||
expect(authTokenSaved.lastUsed).toBeNull();
|
||||
expect(authTokenSaved.lastUsedAt).toBeNull();
|
||||
return authTokenSaved;
|
||||
},
|
||||
);
|
||||
|
@ -273,7 +273,7 @@ describe('AuthService', () => {
|
|||
);
|
||||
expect(token.label).toEqual(identifier);
|
||||
expect(token.validUntil.getTime()).toEqual(validUntil);
|
||||
expect(token.lastUsed).toBeNull();
|
||||
expect(token.lastUsedAt).toBeNull();
|
||||
expect(token.secret.startsWith(token.keyId)).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
@ -290,7 +290,7 @@ describe('AuthService', () => {
|
|||
authToken.validUntil = new Date();
|
||||
const tokenDto = service.toAuthTokenDto(authToken);
|
||||
expect(tokenDto.keyId).toEqual(authToken.keyId);
|
||||
expect(tokenDto.lastUsed).toBeNull();
|
||||
expect(tokenDto.lastUsedAt).toBeNull();
|
||||
expect(tokenDto.label).toEqual(authToken.label);
|
||||
expect(tokenDto.validUntil.getTime()).toEqual(
|
||||
authToken.validUntil.getTime(),
|
||||
|
|
|
@ -108,7 +108,7 @@ export class AuthService {
|
|||
if (accessToken === undefined) {
|
||||
throw new NotInDBError(`AuthToken for key '${keyId}' not found`);
|
||||
}
|
||||
accessToken.lastUsed = new Date();
|
||||
accessToken.lastUsedAt = new Date();
|
||||
await this.authTokenRepository.save(accessToken);
|
||||
}
|
||||
|
||||
|
@ -175,11 +175,11 @@ export class AuthService {
|
|||
keyId: authToken.keyId,
|
||||
createdAt: authToken.createdAt,
|
||||
validUntil: authToken.validUntil,
|
||||
lastUsed: null,
|
||||
lastUsedAt: null,
|
||||
};
|
||||
|
||||
if (authToken.lastUsed) {
|
||||
tokenDto.lastUsed = new Date(authToken.lastUsed);
|
||||
if (authToken.lastUsedAt) {
|
||||
tokenDto.lastUsedAt = new Date(authToken.lastUsedAt);
|
||||
}
|
||||
|
||||
return tokenDto;
|
||||
|
|
|
@ -29,7 +29,7 @@ export class HistoryEntryDto {
|
|||
*/
|
||||
@IsDate()
|
||||
@ApiProperty()
|
||||
lastVisited: Date;
|
||||
lastVisitedAt: Date;
|
||||
|
||||
@IsArray()
|
||||
@IsString({ each: true })
|
||||
|
|
|
@ -189,7 +189,7 @@ export class HistoryService {
|
|||
async toHistoryEntryDto(entry: HistoryEntry): Promise<HistoryEntryDto> {
|
||||
return {
|
||||
identifier: await getIdentifier(entry),
|
||||
lastVisited: entry.updatedAt,
|
||||
lastVisitedAt: entry.updatedAt,
|
||||
tags: await this.notesService.toTagList(entry.note),
|
||||
title: entry.note.title ?? '',
|
||||
pinStatus: entry.pinStatus,
|
||||
|
|
|
@ -72,7 +72,7 @@ export class NoteMetadataDto {
|
|||
*/
|
||||
@IsDate()
|
||||
@ApiProperty()
|
||||
updateTime: Date;
|
||||
updatedAt: Date;
|
||||
|
||||
/**
|
||||
* User that last edited the note
|
||||
|
@ -96,7 +96,7 @@ export class NoteMetadataDto {
|
|||
*/
|
||||
@IsDate()
|
||||
@ApiProperty()
|
||||
createTime: Date;
|
||||
createdAt: Date;
|
||||
|
||||
/**
|
||||
* List of usernames that edited the note
|
||||
|
|
|
@ -773,7 +773,7 @@ describe('NotesService', () => {
|
|||
expect(metadataDto.aliases).toHaveLength(1);
|
||||
expect(metadataDto.aliases[0]).toEqual((await note.aliases)[0].name);
|
||||
expect(metadataDto.title).toEqual(note.title);
|
||||
expect(metadataDto.createTime).toEqual(revisions[0].createdAt);
|
||||
expect(metadataDto.createdAt).toEqual(revisions[0].createdAt);
|
||||
expect(metadataDto.description).toEqual(note.description);
|
||||
expect(metadataDto.editedBy).toHaveLength(1);
|
||||
expect(metadataDto.editedBy[0]).toEqual(user.username);
|
||||
|
@ -790,7 +790,7 @@ describe('NotesService', () => {
|
|||
expect(metadataDto.permissions.sharedToGroups[0].canEdit).toEqual(true);
|
||||
expect(metadataDto.tags).toHaveLength(1);
|
||||
expect(metadataDto.tags[0]).toEqual((await note.tags)[0].name);
|
||||
expect(metadataDto.updateTime).toEqual(revisions[0].createdAt);
|
||||
expect(metadataDto.updatedAt).toEqual(revisions[0].createdAt);
|
||||
expect(metadataDto.updateUser.username).toEqual(user.username);
|
||||
expect(metadataDto.viewCount).toEqual(note.viewCount);
|
||||
});
|
||||
|
@ -875,7 +875,7 @@ describe('NotesService', () => {
|
|||
expect(noteDto.metadata.aliases).toHaveLength(1);
|
||||
expect(noteDto.metadata.aliases[0]).toEqual((await note.aliases)[0].name);
|
||||
expect(noteDto.metadata.title).toEqual(note.title);
|
||||
expect(noteDto.metadata.createTime).toEqual(revisions[0].createdAt);
|
||||
expect(noteDto.metadata.createdAt).toEqual(revisions[0].createdAt);
|
||||
expect(noteDto.metadata.description).toEqual(note.description);
|
||||
expect(noteDto.metadata.editedBy).toHaveLength(1);
|
||||
expect(noteDto.metadata.editedBy[0]).toEqual(user.username);
|
||||
|
@ -898,7 +898,7 @@ describe('NotesService', () => {
|
|||
);
|
||||
expect(noteDto.metadata.tags).toHaveLength(1);
|
||||
expect(noteDto.metadata.tags[0]).toEqual((await note.tags)[0].name);
|
||||
expect(noteDto.metadata.updateTime).toEqual(revisions[0].createdAt);
|
||||
expect(noteDto.metadata.updatedAt).toEqual(revisions[0].createdAt);
|
||||
expect(noteDto.metadata.updateUser.username).toEqual(user.username);
|
||||
expect(noteDto.metadata.viewCount).toEqual(note.viewCount);
|
||||
expect(noteDto.content).toEqual(content);
|
||||
|
|
|
@ -400,12 +400,12 @@ export class NotesService {
|
|||
),
|
||||
primaryAlias: (await getPrimaryAlias(note)) ?? null,
|
||||
title: note.title ?? '',
|
||||
createTime: (await this.getFirstRevision(note)).createdAt,
|
||||
createdAt: (await this.getFirstRevision(note)).createdAt,
|
||||
description: note.description ?? '',
|
||||
editedBy: (await this.getAuthorUsers(note)).map((user) => user.username),
|
||||
permissions: await this.toNotePermissionsDto(note),
|
||||
tags: await this.toTagList(note),
|
||||
updateTime: (await this.getLatestRevision(note)).createdAt,
|
||||
updatedAt: (await this.getLatestRevision(note)).createdAt,
|
||||
updateUser: updateUser ? this.usersService.toUserDto(updateUser) : null,
|
||||
viewCount: note.viewCount,
|
||||
};
|
||||
|
|
|
@ -79,8 +79,8 @@ describe('History', () => {
|
|||
expect(response.body[0].title).toEqual(entryDto.title);
|
||||
expect(response.body[0].tags).toEqual(entryDto.tags);
|
||||
expect(response.body[0].pinStatus).toEqual(entryDto.pinStatus);
|
||||
expect(response.body[0].lastVisited).toEqual(
|
||||
entryDto.lastVisited.toISOString(),
|
||||
expect(response.body[0].lastVisitedAt).toEqual(
|
||||
entryDto.lastVisitedAt.toISOString(),
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -218,7 +218,7 @@ describe('History', () => {
|
|||
expect(userEntryDto.title).toEqual(entryDto.title);
|
||||
expect(userEntryDto.tags).toEqual(entryDto.tags);
|
||||
expect(userEntryDto.pinStatus).toEqual(entryDto.pinStatus);
|
||||
expect(userEntryDto.lastVisited).toEqual(entryDto.lastVisited);
|
||||
expect(userEntryDto.lastVisitedAt).toEqual(entryDto.lastVisitedAt);
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
|
|
|
@ -47,7 +47,7 @@ describe('Tokens', () => {
|
|||
keyId = response.body.keyId;
|
||||
expect(response.body.label).toBe(tokenName);
|
||||
expect(response.body.validUntil).toBe(null);
|
||||
expect(response.body.lastUsed).toBe(null);
|
||||
expect(response.body.lastUsedAt).toBe(null);
|
||||
expect(response.body.secret.length).toBe(98);
|
||||
});
|
||||
|
||||
|
@ -59,7 +59,7 @@ describe('Tokens', () => {
|
|||
.expect(200);
|
||||
expect(response.body[0].label).toBe(tokenName);
|
||||
expect(response.body[0].validUntil).toBe(null);
|
||||
expect(response.body[0].lastUsed).toBe(null);
|
||||
expect(response.body[0].lastUsedAt).toBe(null);
|
||||
expect(response.body[0].secret).not.toBeDefined();
|
||||
});
|
||||
it(`DELETE /tokens/:keyid`, async () => {
|
||||
|
|
|
@ -59,8 +59,8 @@ describe('Me', () => {
|
|||
expect(historyEntry.title).toEqual(historyDto.title);
|
||||
expect(historyEntry.tags).toEqual(historyDto.tags);
|
||||
expect(historyEntry.pinStatus).toEqual(historyDto.pinStatus);
|
||||
expect(historyEntry.lastVisited).toEqual(
|
||||
historyDto.lastVisited.toISOString(),
|
||||
expect(historyEntry.lastVisitedAt).toEqual(
|
||||
historyDto.lastVisitedAt.toISOString(),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
@ -83,8 +83,8 @@ describe('Me', () => {
|
|||
expect(historyEntry.title).toEqual(historyEntryDto.title);
|
||||
expect(historyEntry.tags).toEqual(historyEntryDto.tags);
|
||||
expect(historyEntry.pinStatus).toEqual(historyEntryDto.pinStatus);
|
||||
expect(historyEntry.lastVisited).toEqual(
|
||||
historyEntryDto.lastVisited.toISOString(),
|
||||
expect(historyEntry.lastVisitedAt).toEqual(
|
||||
historyEntryDto.lastVisitedAt.toISOString(),
|
||||
);
|
||||
});
|
||||
it('fails with a non-existing note', async () => {
|
||||
|
|
|
@ -274,13 +274,13 @@ describe('Notes', () => {
|
|||
expect(metadata.body.primaryAlias).toEqual('test5');
|
||||
expect(metadata.body.title).toEqual('');
|
||||
expect(metadata.body.description).toEqual('');
|
||||
expect(typeof metadata.body.createTime).toEqual('string');
|
||||
expect(typeof metadata.body.createdAt).toEqual('string');
|
||||
expect(metadata.body.editedBy).toEqual([]);
|
||||
expect(metadata.body.permissions.owner.username).toEqual('hardcoded');
|
||||
expect(metadata.body.permissions.sharedToUsers).toEqual([]);
|
||||
expect(metadata.body.permissions.sharedToUsers).toEqual([]);
|
||||
expect(metadata.body.tags).toEqual([]);
|
||||
expect(typeof metadata.body.updateTime).toEqual('string');
|
||||
expect(typeof metadata.body.updatedAt).toEqual('string');
|
||||
expect(typeof metadata.body.updateUser.displayName).toEqual('string');
|
||||
expect(typeof metadata.body.updateUser.username).toEqual('string');
|
||||
expect(typeof metadata.body.updateUser.email).toEqual('string');
|
||||
|
@ -320,7 +320,7 @@ describe('Notes', () => {
|
|||
const metadata = await request(testSetup.app.getHttpServer())
|
||||
.get('/api/v2/notes/test5a/metadata')
|
||||
.expect(200);
|
||||
expect(metadata.body.createTime).toEqual(createDate.toISOString());
|
||||
expect(metadata.body.createdAt).toEqual(createDate.toISOString());
|
||||
expect(metadata.body.updateTime).not.toEqual(createDate.toISOString());
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue