Skip to content

Commit

Permalink
fix(shared-data): fix "strict" arg for labware creation (#3874)
Browse files Browse the repository at this point in the history
  • Loading branch information
IanLondon authored Aug 16, 2019
1 parent 9ab6938 commit bd604e2
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`test createIrregularLabware function failing to validate against labware schema throws w/o "strict" 1`] = `"Generated labware failed to validate, please check your inputs"`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`createLabware failing to validate against labware schema throws w/o "strict" 1`] = `"Generated labware failed to validate, please check your inputs"`;
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ describe('test helper functions', () => {

describe('test createIrregularLabware function', () => {
let labware1

let labware1Args
beforeEach(() => {
labware1 = createIrregularLabware({
labware1Args = {
namespace: 'fixture',
metadata: {
displayName: 'Fake Irregular Container',
Expand Down Expand Up @@ -125,7 +125,8 @@ describe('test createIrregularLabware function', () => {
{ rowStart: 'A', colStart: '1', rowStride: 2, colStride: 1 },
{ rowStart: 'B', colStart: '1', rowStride: 1, colStride: 1 },
],
})
}
labware1 = createIrregularLabware(labware1Args)
})

test('irregular ordering generates as expected', () => {
Expand Down Expand Up @@ -174,4 +175,17 @@ describe('test createIrregularLabware function', () => {

expect(loadName).toEqual('somebrand_6_wellplate_6x4ml')
})

test('failing to validate against labware schema throws w/o "strict"', () => {
const args = {
...labware1Args,
// negative y offset should fail schema validation by making well `y` negative
offset: [{ x: 10, y: -9999, z: 69.48 }, { x: 15, y: -9999, z: 69.48 }],
}

expect(() => createIrregularLabware(args)).toThrowErrorMatchingSnapshot()
expect(() =>
createIrregularLabware({ ...args, strict: false })
).not.toThrow()
})
})
17 changes: 15 additions & 2 deletions shared-data/js/labwareTools/__tests__/createLabware.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const exampleLabware2 = {
describe('createLabware', () => {
let labware1
let labware2
let labware2Args
let well1
let well2
let offset1
Expand All @@ -49,7 +50,7 @@ describe('createLabware', () => {
namespace: 'fixture',
})

labware2 = createRegularLabware({
labware2Args = {
metadata: exampleLabware2.metadata,
parameters: exampleLabware2.parameters,
dimensions: exampleLabware2.dimensions,
Expand All @@ -58,7 +59,8 @@ describe('createLabware', () => {
spacing: { row: 10, column: 10 },
well: well2,
namespace: 'fixture',
})
}
labware2 = createRegularLabware(labware2Args)
})

afterEach(() => {
Expand Down Expand Up @@ -110,4 +112,15 @@ describe('createLabware', () => {
})
})
})

test('failing to validate against labware schema throws w/o "strict"', () => {
const args = {
...labware2Args,
// this spacing should make negative well `y` value and fail schema validation
spacing: { row: 999, column: 999 },
}

expect(() => createRegularLabware(args)).toThrowErrorMatchingSnapshot()
expect(() => createRegularLabware({ ...args, strict: false })).not.toThrow()
})
})
6 changes: 3 additions & 3 deletions shared-data/js/labwareTools/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const validate = ajv.compile(labwareSchema)

function validateDefinition(
definition: Definition,
strict: boolean = true
strict: ?boolean = true
): Definition {
const valid = validate(definition)

Expand Down Expand Up @@ -328,7 +328,7 @@ export function createDefaultDisplayName(args: RegularNameProps): string {
// or the labware definition schema in labware/schemas/
export function createRegularLabware(args: RegularLabwareProps): Definition {
const { offset, dimensions, grid, spacing, well, loadNamePostfix } = args
const strict = args.strict || true
const strict = args.strict
const version = args.version || 1
const namespace = args.namespace || DEFAULT_CUSTOM_NAMESPACE
const ordering = determineOrdering(grid)
Expand Down Expand Up @@ -372,7 +372,7 @@ export function createIrregularLabware(
args: IrregularLabwareProps
): Definition {
const { offset, dimensions, grid, spacing, well, gridStart, group } = args
const strict = args.strict || true
const strict = args.strict
const namespace = args.namespace || DEFAULT_CUSTOM_NAMESPACE
const version = args.version || 1
const { wells, groups } = determineIrregularLayout(
Expand Down

0 comments on commit bd604e2

Please sign in to comment.