Skip to content

Commit

Permalink
set remote id correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
develohpanda committed Jun 3, 2021
1 parent 4cc56cd commit 10face2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/insomnia-app/app/models/space.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type Space = BaseModel & BaseSpace;
export function init(): BaseSpace {
return {
name: 'My Space',
remoteId: undefined, // this is necessary for the model init logic to work properly
};
}

Expand Down
20 changes: 17 additions & 3 deletions packages/insomnia-app/app/ui/hooks/__tests__/space.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import VCS from '../../../sync/vcs';
import { globalBeforeEach } from '../../../__jest__/before-each';
import { useRemoteSpaces } from '../space';
import * as models from '../../../models';
import { Space } from '../../../models/space';

jest.mock('../../../account/session', () => ({
isLoggedIn: jest.fn(),
Expand Down Expand Up @@ -39,8 +40,10 @@ describe('useRemoteSpaces', () => {

const vcs1 = new VCS(new MemoryDriver());
const vcs2 = new VCS(new MemoryDriver());
(vcs1.teams as jest.MockedFunction<typeof vcs1.teams>).mockResolvedValue([{ id: 'id1', name: 'name' }]);
(vcs2.teams as jest.MockedFunction<typeof vcs2.teams>).mockResolvedValue([{ id: 'id2', name: 'name' }]);
const team1 = { id: 'id1', name: 'team1' };
const team2 = { id: 'id1', name: 'team2' };
(vcs1.teams as jest.MockedFunction<typeof vcs1.teams>).mockResolvedValue([team1]);
(vcs2.teams as jest.MockedFunction<typeof vcs2.teams>).mockResolvedValue([team2]);

const { result, rerender, waitFor } = renderHook(prop => useRemoteSpaces(prop), { initialProps: vcs1 });

Expand All @@ -58,7 +61,18 @@ describe('useRemoteSpaces', () => {

expect(vcs2.teams).toHaveBeenCalledTimes(1);

await expect(models.space.all()).resolves.toHaveLength(2);
const allSpaces = await models.space.all();
expect(allSpaces).toHaveLength(2);
expect(allSpaces).toEqual(expect.arrayContaining([
expect.objectContaining<Partial<Space>>({
remoteId: team1.id,
name: team1.name,
}),
expect.objectContaining<Partial<Space>>({
remoteId: team2.id,
name: team2.name,
}),
]));
});

it('should load teams on refresh', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/insomnia-app/app/ui/hooks/space.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const useRemoteSpaces = (vcs?: VCS) => {
setLoading(true);

const teams = await vcs.teams();
const spaces = await Promise.all(teams.map(team => models.initModel<Space>(models.space.type, { _id: team.id, name: team.name })));
const spaces = await Promise.all(teams.map(team => models.initModel<Space>(models.space.type, { remoteId: team.id, name: team.name })));
await database.batchModifyDocs({ upsert: spaces });

setLoading(false);
Expand Down

0 comments on commit 10face2

Please sign in to comment.