Skip to content

Commit

Permalink
fix snapshot issue and update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gatzjames committed Mar 8, 2024
1 parent b564080 commit f96fdce
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 47 deletions.
101 changes: 55 additions & 46 deletions packages/insomnia/src/sync/vcs/__tests__/vcs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,9 @@ describe('VCS', () => {
document: newDoc('qux'),
},
],
{},
);
expect(status).toEqual({
key: 'a156b75bc8fd5ad4e0e3da036c30667af631cf2b',
key: '6dbc95d09d310cf9d8561bc46da440d8197c3bf1',
stage: {},
unstaged: {
foo: {
Expand All @@ -60,13 +59,15 @@ describe('VCS', () => {
blobContent: '{"_id":"bar","created":1234,"isPrivate":false,"name":"name","parentId":"","type":"base"}',
blobId: 'f084c7823f01300890d0d6539cfaffa5e2398da1',
name: 'Foo',
previousBlobContent: 'null',
},
baz: {
added: true,
key: 'baz',
blobContent: '{"_id":"qux","created":1234,"isPrivate":false,"name":"name","parentId":"","type":"base"}',
blobId: 'aee296597cedfbfe6c961b0c48a5e05c6acb1da3',
name: 'Baz',
previousBlobContent: 'null',
},
},
});
Expand Down Expand Up @@ -95,8 +96,8 @@ describe('VCS', () => {
{},
);
expect(Object.keys(status1.unstaged)).toEqual(['a', 'b', 'c']);
const stageResult = await v.stage(status1.stage, [status1.unstaged.a, status1.unstaged.b, status1.unstaged.c]);
await v.takeSnapshot(stageResult, 'Add a/b/c');
await v.stage([status1.unstaged.a, status1.unstaged.b, status1.unstaged.c]);
await v.takeSnapshot('Add a/b/c');
const history = await v.getHistory();
expect(history.length).toBe(1);
expect(history).toEqual([
Expand Down Expand Up @@ -153,39 +154,43 @@ describe('VCS', () => {
{},
);
expect(status).toEqual({
key: 'dc9ac9680eabf62d94d63c862d5b863453c4fc72',
key: '3314d88d8a8c307083414ca93b2e35bc5233e292',
stage: {},
unstaged: {
a: {
deleted: true,
blobId: '4a1582f059cf4cc4c4dcd56e893b9ae88f32125d',
key: 'a',
name: 'A',
previousBlobContent: '{\"_id\":\"aaa\",\"created\":1234,\"isPrivate\":false,\"name\":\"name\",\"parentId\":\"\",\"type\":\"base\"}',
},
notA: {
added: true,
key: 'notA',
name: 'Not A',
blobId: '4a1582f059cf4cc4c4dcd56e893b9ae88f32125d',
blobContent: '{"_id":"aaa","created":1234,"isPrivate":false,"name":"name","parentId":"","type":"base"}',
previousBlobContent: 'null',
},
c: {
modified: true,
key: 'c',
name: 'C',
blobId: '87a13a793c6bc2137732ba4f8dc8d877fc143bad',
blobContent: '{"_id":"modified","created":1234,"isPrivate":false,"name":"name","parentId":"","type":"base"}',
previousBlobContent: '{\"_id\":\"ccc\",\"created\":1234,\"isPrivate\":false,\"name\":\"name\",\"parentId\":\"\",\"type\":\"base\"}',
},
d: {
added: true,
key: 'd',
name: 'D',
blobId: 'cb6c7a2814104ff614133076245ae32fe9a62c8f',
blobContent: '{"_id":"ddd","created":1234,"isPrivate":false,"name":"name","parentId":"","type":"base"}',
previousBlobContent: 'null',
},
},
});
const newStage = await v.stage(status.stage, [
await v.stage([
status.unstaged.a,
status.unstaged.notA,
status.unstaged.c,
Expand Down Expand Up @@ -213,38 +218,41 @@ describe('VCS', () => {
name: 'D',
document: newDoc('ddd'),
},
],
newStage,
]
);
expect(status2).toEqual({
key: 'fa7e77538196bd6c337d9271b2a3af87abde3e15',
key: '872dd92bb678f7e26b8610e4d37c0438f2f04beb',
stage: {
a: {
deleted: true,
blobId: '4a1582f059cf4cc4c4dcd56e893b9ae88f32125d',
key: 'a',
name: 'A',
previousBlobContent: '{\"_id\":\"aaa\",\"created\":1234,\"isPrivate\":false,\"name\":\"name\",\"parentId\":\"\",\"type\":\"base\"}',
},
notA: {
added: true,
blobId: '4a1582f059cf4cc4c4dcd56e893b9ae88f32125d',
key: 'notA',
name: 'Not A',
blobContent: '{"_id":"aaa","created":1234,"isPrivate":false,"name":"name","parentId":"","type":"base"}',
previousBlobContent: 'null',
},
c: {
modified: true,
blobId: '87a13a793c6bc2137732ba4f8dc8d877fc143bad',
key: 'c',
name: 'C',
blobContent: '{"_id":"modified","created":1234,"isPrivate":false,"name":"name","parentId":"","type":"base"}',
previousBlobContent: '{\"_id\":\"ccc\",\"created\":1234,\"isPrivate\":false,\"name\":\"name\",\"parentId\":\"\",\"type\":\"base\"}',
},
d: {
added: true,
blobId: 'cb6c7a2814104ff614133076245ae32fe9a62c8f',
key: 'd',
name: 'D',
blobContent: '{"_id":"ddd","created":1234,"isPrivate":false,"name":"name","parentId":"","type":"base"}',
previousBlobContent: 'null',
},
},
unstaged: {},
Expand All @@ -268,7 +276,7 @@ describe('VCS', () => {
],
{},
);
const stage = await v.stage(status.stage, [status.unstaged.a]);
await v.stage([status.unstaged.a]);
const status2 = await v.status(
[
{
Expand All @@ -282,17 +290,17 @@ describe('VCS', () => {
document: newDoc('bbb'),
},
],
stage,
);
expect(status2).toEqual({
key: 'f92908bb0e471e61e0903b8c669f9d20e8d7c8f0',
key: '7e7b488b9010839218f8e8c7d1d48b0e0e6b5f8c',
stage: {
a: {
added: true,
blobId: '4a1582f059cf4cc4c4dcd56e893b9ae88f32125d',
name: 'A',
key: 'a',
blobContent: '{"_id":"aaa","created":1234,"isPrivate":false,"name":"name","parentId":"","type":"base"}',
previousBlobContent: 'null',
},
},
unstaged: {
Expand All @@ -302,13 +310,15 @@ describe('VCS', () => {
key: 'a',
name: 'A',
blobContent: '{"_id":"modified","created":1234,"isPrivate":false,"name":"name","parentId":"","type":"base"}',
previousBlobContent: '{\"_id\":\"aaa\",\"created\":1234,\"isPrivate\":false,\"name\":\"name\",\"parentId\":\"\",\"type\":\"base\"}',
},
b: {
added: true,
blobId: 'd42a1e9b61f31d85f54981d976aea411864c13c0',
name: 'B',
key: 'b',
blobContent: '{"_id":"bbb","created":1234,"isPrivate":false,"name":"name","parentId":"","type":"base"}',
previousBlobContent: 'null',
},
},
});
Expand All @@ -326,8 +336,8 @@ describe('VCS', () => {
],
{},
);
const stage2 = await v.stage(status.stage, [status.unstaged.foo]);
await v.takeSnapshot(stage2, 'Add foo');
await v.stage([status.unstaged.foo]);
await v.takeSnapshot('Add foo');
const status2 = await v.status(
[
{
Expand Down Expand Up @@ -364,14 +374,15 @@ describe('VCS', () => {
],
{},
);
const stage = await v.stage(status.stage, [status.unstaged.foo]);
const stage = await v.stage([status.unstaged.foo]);
expect(stage).toEqual({
foo: {
key: 'foo',
name: 'Foo',
blobContent: '{"_id":"bar","created":1234,"isPrivate":false,"name":"name","parentId":"","type":"base"}',
blobId: 'f084c7823f01300890d0d6539cfaffa5e2398da1',
added: true,
previousBlobContent: 'null',
},
});
const status2 = await v.status(
Expand All @@ -387,17 +398,17 @@ describe('VCS', () => {
document: newDoc('qux'),
},
],
stage,
);
expect(status2).toEqual({
key: '83dfd47a77c5015169d611f6559b18ea588ad89a',
key: 'cfd47b8a7d50f39dfa1ca956ac2ab60427d6351b',
stage: {
foo: {
name: 'Foo',
key: 'foo',
blobContent: '{"_id":"bar","created":1234,"isPrivate":false,"name":"name","parentId":"","type":"base"}',
blobId: 'f084c7823f01300890d0d6539cfaffa5e2398da1',
added: true,
previousBlobContent: 'null',
},
},
unstaged: {
Expand All @@ -407,6 +418,7 @@ describe('VCS', () => {
blobContent: '{"_id":"qux","created":1234,"isPrivate":false,"name":"name","parentId":"","type":"base"}',
blobId: 'aee296597cedfbfe6c961b0c48a5e05c6acb1da3',
added: true,
previousBlobContent: 'null',
},
},
});
Expand All @@ -426,8 +438,8 @@ describe('VCS', () => {
],
{},
);
const stage = await v.stage(status.stage, [status.unstaged.foo]);
await v.takeSnapshot(stage, 'Add foo');
await v.stage([status.unstaged.foo]);
await v.takeSnapshot('Add foo');
const history = await v.getHistory();
expect(history).toEqual([
{
Expand Down Expand Up @@ -458,10 +470,9 @@ describe('VCS', () => {
document: newDoc('bar'),
},
],
{},
);
const stage = await v.stage(status.stage, [status.unstaged.foo]);
await v.takeSnapshot(stage, 'Add foo');
await v.stage([status.unstaged.foo]);
await v.takeSnapshot('Add foo');
const history = await v.getHistory();
expect(history).toEqual([
{
Expand All @@ -480,9 +491,9 @@ describe('VCS', () => {
],
},
]);
const status2 = await v.status([], {});
const stage2 = await v.stage(status2.stage, [status2.unstaged.foo]);
await v.takeSnapshot(stage2, 'Delete foo');
const status2 = await v.status([]);
await v.stage([status2.unstaged.foo]);
await v.takeSnapshot('Delete foo');
const history2 = await v.getHistory();
expect(history2).toEqual([
{
Expand Down Expand Up @@ -562,10 +573,9 @@ describe('VCS', () => {
document: newDoc('bar'),
},
],
{},
);
const stage1 = await v.stage(status1.stage, [status1.unstaged.foo]);
await v.takeSnapshot(stage1, 'Add foo');
await v.stage([status1.unstaged.foo]);
await v.takeSnapshot('Add foo');
// Checkout branch
await v.checkout([], 'new-branch');
expect(await v.getBranches()).toEqual(['master', 'new-branch']);
Expand All @@ -590,8 +600,8 @@ describe('VCS', () => {
],
{},
);
const stage1 = await v.stage(status1.stage, [status1.unstaged.foo]);
await v.takeSnapshot(stage1, 'Add foo');
await v.stage([status1.unstaged.foo]);
await v.takeSnapshot('Add foo');
// Checkout branch
await v.fork('new-branch');
await v.checkout([], 'new-branch');
Expand Down Expand Up @@ -635,8 +645,8 @@ describe('VCS', () => {
],
{},
);
const stage1 = await v.stage(status1.stage, [status1.unstaged.a, status1.unstaged.b]);
await v.takeSnapshot(stage1, 'Add A and B');
await v.stage([status1.unstaged.a, status1.unstaged.b]);
await v.takeSnapshot('Add A and B');
expect((await v.getHistory())[0].state).toEqual([
expect.objectContaining({
key: 'a',
Expand Down Expand Up @@ -664,11 +674,10 @@ describe('VCS', () => {
name: 'C',
document: newDoc('ccc'),
},
],
status1.stage,
]
);
const stage2 = await v.stage(status2.stage, [status2.unstaged.b, status2.unstaged.c]);
await v.takeSnapshot(stage2, 'Add C, modify B');
await v.stage([status2.unstaged.b, status2.unstaged.c]);
await v.takeSnapshot('Add C, modify B');
expect((await v.getHistory())[1].state).toEqual(
expect.arrayContaining([
expect.objectContaining({
Expand Down Expand Up @@ -701,8 +710,8 @@ describe('VCS', () => {
],
{},
);
const stage1 = await v.stage(status1.stage, [status1.unstaged.a, status1.unstaged.b]);
await v.takeSnapshot(stage1, 'message');
await v.stage([status1.unstaged.a, status1.unstaged.b]);
await v.takeSnapshot('message');
});

it('does something', async () => {
Expand All @@ -719,8 +728,8 @@ describe('VCS', () => {
],
{},
);
const stage = await v.stage(status1.stage, [status1.unstaged.a]);
await v.takeSnapshot(stage, 'Add A');
await v.stage([status1.unstaged.a]);
await v.takeSnapshot('Add A');
expect(await v.getHistory()).toEqual([
{
id: '03ac0d9058614e1cafc6c53553bd0924b03f0b53',
Expand Down Expand Up @@ -752,8 +761,8 @@ describe('VCS', () => {
],
{},
);
const stage2 = await v.stage(status2.stage, [status2.unstaged.b]);
await v.takeSnapshot(stage2, 'Add B');
await v.stage([status2.unstaged.b]);
await v.takeSnapshot('Add B');
expect(await v.getHistory()).toEqual([
{
id: '03ac0d9058614e1cafc6c53553bd0924b03f0b53',
Expand Down Expand Up @@ -870,8 +879,8 @@ describe('VCS', () => {
],
{},
);
const stage1 = await v.stage(status1.stage, [status1.unstaged.foo]);
await v.takeSnapshot(stage1, 'Add foo');
await v.stage([status1.unstaged.foo]);
await v.takeSnapshot('Add foo');
const status2 = await v.status(
[
{
Expand All @@ -882,8 +891,8 @@ describe('VCS', () => {
],
{},
);
const stage2 = await v.stage(status2.stage, [status2.unstaged.bar]);
await v.takeSnapshot(stage2, 'Add bar');
await v.stage([status2.unstaged.bar]);
await v.takeSnapshot('Add bar');
});

it('returns all history', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/insomnia/src/sync/vcs/vcs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export class VCS {
};
}
} else {
const blobId = snapshot.state.find(s => s.key === key)?.blob || '';
const blobId = snapshot ? snapshot.state.find(s => s.key === key)?.blob || '' : '';
let previousBlobContent: BaseModel | null = null;
try {
previousBlobContent = (await this._getBlob(blobId)) || null;
Expand Down

0 comments on commit f96fdce

Please sign in to comment.