Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(shared-data): fix "strict" arg for labware creation #3874

Merged
merged 1 commit into from
Aug 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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