Skip to content

Commit fe8f6e3

Browse files
test(db): cover removeUserCanAuthorise lastModified bump
NeDB adaptor already bumps lastModified on all user-role mutations; extend #1486 date-field tests to assert removeUserCanAuthorise preserves dateCreated while advancing lastModified. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 065fab5 commit fe8f6e3

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

test/db/repo.date-fields.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,35 @@ describe('Repo dateCreated / lastModified (#1486)', () => {
8181
expect(updatedDoc!.users.canPush).toContain('alice');
8282
});
8383

84+
it('removeUserCanAuthorise bumps lastModified but leaves dateCreated unchanged', async () => {
85+
const existing: Repo = {
86+
project: 'finos',
87+
name: 'sample',
88+
url: 'https://github.com/finos/sample.git',
89+
users: { canPush: [], canAuthorise: ['bob'] },
90+
dateCreated: '2020-01-01T00:00:00.000Z',
91+
lastModified: '2020-01-01T00:00:00.000Z',
92+
_id: 'abc',
93+
};
94+
95+
vi.spyOn(repoModule.db, 'findOne').mockImplementation((_: unknown, cb: any) =>
96+
cb(null, { ...existing }),
97+
);
98+
let updatedDoc: Repo | null = null;
99+
vi.spyOn(repoModule.db, 'update').mockImplementation(
100+
(_q: unknown, doc: any, _o: unknown, cb: any) => {
101+
updatedDoc = doc;
102+
cb(null, 1);
103+
},
104+
);
105+
106+
await repoModule.removeUserCanAuthorise('abc', 'bob');
107+
108+
expect(updatedDoc!.dateCreated).toBe('2020-01-01T00:00:00.000Z');
109+
expect(updatedDoc!.lastModified).not.toBe('2020-01-01T00:00:00.000Z');
110+
expect(updatedDoc!.users.canAuthorise).not.toContain('bob');
111+
});
112+
84113
it('sort by dateCreated orders oldest → newest (asc)', () => {
85114
const repos: Pick<Repo, 'name' | 'dateCreated'>[] = [
86115
{ name: 'zeta', dateCreated: '2024-06-01T00:00:00.000Z' },

0 commit comments

Comments
 (0)