Skip to content

Commit

Permalink
Fixes bug with v1_2 format (#521)
Browse files Browse the repository at this point in the history
* Fixes bug with v1_2

* place updateFn in correct place

* fix tests; add v1_1 -> v1_2 test
  • Loading branch information
davidfig committed May 21, 2023
1 parent 3ad0967 commit 1d495f8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
41 changes: 34 additions & 7 deletions src/schemas/validateGridFile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import fs from 'fs';
import path from 'path';
import { GridFiles } from '.';
import { GridFileV1 } from './GridFileV1';
import { GridFileV1_1 } from './GridFileV1_1';
import { validateGridFile } from './validateGridFile';
import { GridFileV1_2 } from './GridFileV1_2';
import { GridFileV1_1 } from './GridFileV1_1';
import { randomUUID } from 'crypto';
const v = validateGridFile;
const EXAMPLES_DIR = path.join(__dirname, '../../public/examples/');
const exampleGridFiles: GridFiles[] = fs
Expand Down Expand Up @@ -31,6 +33,21 @@ const v1File: GridFileV1 = {
render_dependency: [],
};

const v1_1File: GridFileV1_1 = {
version: '1.1',
cells: [],
columns: [],
rows: [],
borders: [],
cell_dependency: 'foo',
formats: [],
render_dependency: [],
id: randomUUID(),
created: 1,
filename: '1',
modified: 1,
};

describe('validateFile()', () => {
// TODO test the round trip of import to export to import

Expand Down Expand Up @@ -61,9 +78,10 @@ describe('validateFile()', () => {
expect(v(v1FileSansCellDependency)).not.toBe(null);
});

test('Upgrades a valid file from v1 to v1.1', () => {
test('Upgrades a valid file from v1 to v1.2', () => {
const result = v(v1File);
expect(result).toHaveProperty('version', '1.1');
expect(result).not.toBeNull();
expect(result).toHaveProperty('version', '1.2');
expect(result).toHaveProperty('modified');
expect(result).toHaveProperty('created');
expect(result).toHaveProperty('id');
Expand All @@ -79,21 +97,30 @@ describe('validateFile()', () => {
expect(result).not.toHaveProperty('borders[7].horizontal');
});

test('Upgrades a valid file from v1.1 to v1.2', () => {
const result = v(v1_1File);
expect(result).not.toBeNull();
expect(result).toHaveProperty('version', '1.2');
expect(result).toHaveProperty('modified');
expect(result).toHaveProperty('created');
expect(result).toHaveProperty('id');
expect(result).toHaveProperty('filename');
});

test('Returns the file when it matches the most recent schema', () => {
const v1_1File: GridFileV1_1 = {
version: '1.1',
const v1_2File: GridFileV1_2 = {
version: '1.2',
cells: [],
columns: [],
rows: [],
borders: [{ x: 0, y: 0, horizontal: { type: 'line1' } }],
formats: [{ x: 1, y: 1 }],
render_dependency: [],
cell_dependency: 'foo',
modified: 123,
created: 123,
id: '123e4567-e89b-12d3-a456-426614174000',
filename: 'foo',
};
expect(v(v1_1File)).toStrictEqual(v1_1File);
expect(v(v1_2File)).toStrictEqual(v1_2File);
});
});
7 changes: 6 additions & 1 deletion src/schemas/validateGridFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ import { GridFileSchemaV1 } from './GridFileV1';
import { GridFileSchemaV1_1, upgradeV1toV1_1 } from './GridFileV1_1';
import { GridFile, GridFiles } from '.';
import { debugShowFileIO } from '../debugFlags';
import { GridFileSchemaV1_2, upgradeV1_1toV1_2 } from './GridFileV1_2';

// Ordered by newest first
const files = [{ schema: GridFileSchemaV1_1 }, { schema: GridFileSchemaV1, updateFn: upgradeV1toV1_1 }];
const files = [
{ schema: GridFileSchemaV1_2 },
{ schema: GridFileSchemaV1_1, updateFn: upgradeV1_1toV1_2 },
{ schema: GridFileSchemaV1, updateFn: upgradeV1toV1_1 },
];

/**
* Given arbitrary JSON, validate whether it's a valid file format and return
Expand Down

1 comment on commit 1d495f8

@vercel
Copy link

@vercel vercel bot commented on 1d495f8 May 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

quadratic – ./

quadratic-nu.vercel.app
quadratic-quadratic.vercel.app
quadratic-git-main-quadratic.vercel.app

Please sign in to comment.