Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
cressie176 committed Jan 7, 2024
1 parent f2ea2a0 commit 8b4632c
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 9 deletions.
16 changes: 12 additions & 4 deletions lib/marv-rdf-driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ module.exports = (options) => {
const errors = validate.errors;
const instancePath = errors[0].instancePath || 'migration script';
switch (errors[0].keyword) {
case 'type': {
const fault = errors[0].message
.replace(/be object/, 'be an object')
.replace(/be array/, 'be an array')
message = `${instancePath} ${fault}`
break;
}
case 'required': {
const conjunction = errors.find(e => e.keyword === 'anyOf') ? 'and' : 'or'
const missingProperties = errors.filter(e => e.keyword === 'required')
Expand All @@ -71,11 +78,12 @@ module.exports = (options) => {
: `${instancePath} must have required ${missingProperties.length === 1 ? 'property' : 'properties'} ${missingProperties}`;
break;
}
case 'enum': {
message = `${instancePath} ${errors[0].message}: ${errors[0].params.allowedValues.join(', ')}`
break;
}
default: {
fault = errors[0].message
.replace(/be object/, 'be an object')
.replace(/be array/, 'be an array')
message = `${instancePath} ${fault}`;
message = `${instancePath} ${errors[0].message}`
break;
}
}
Expand Down
3 changes: 1 addition & 2 deletions lib/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,5 @@
]
}
}
},
"required": []
}
}
135 changes: 132 additions & 3 deletions test/dsl.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ describe('DSL', () => {
- name: type
type: TEXT
`), (err) => {
match(err.message, new RegExp("/define_entities/0 must have required property 'identified by' or 'identified_by'"));
match(err.message, new RegExp("/define_entities/0 must have X required property 'identified by' or 'identified_by'"));
return true;
});

Expand All @@ -290,10 +290,139 @@ describe('DSL', () => {
match(err.message, new RegExp("/define_entities/0/identified_by must be an array"));
return true;
});

});
}, { exclusive: true });
});

describe('Change Sets', () => {
it('should require an effective from date', async (t) => {
await rejects(() => apply(t.name, `
add change set:
- frames:
- entity: VAT Rate
version: 1
action: POST
data:
- type: standard
rate: 0.10
`), (err) => {
match(err.message, new RegExp("/add_change_set/0 must have required property 'effective from' or 'effective_from'"));
return true;
})
})

it('should require at least one frame', async (t) => {
await rejects(() => apply(t.name, `
add change set:
- effective from: 2020-04-05T00:00:00.000Z
`), (err) => {
match(err.message, new RegExp("/add_change_set/0 must have required property 'frames'"));
return true;
})

await rejects(() => apply(t.name, `
add change set:
- effective from: 2020-04-05T00:00:00.000Z
frames:
`), (err) => {
match(err.message, new RegExp("/add_change_set/0/frames must be an array"));
return true;
})

})

it('should require frames to specify an entity name', async (t) => {
await rejects(() => apply(t.name, `
add change set:
- effective from: 2020-04-05T00:00:00.000Z
frames:
- version: 1
action: POST
data:
- type: standard
rate: 0.10
`), (err) => {
match(err.message, new RegExp("/add_change_set/0/frames/0 must have required property 'entity'"));
return true;
})
})

it('should require frames to specify an entity version', async (t) => {
await rejects(() => apply(t.name, `
add change set:
- effective from: 2020-04-05T00:00:00.000Z
frames:
- entity: VAT Rate
action: POST
data:
- type: standard
rate: 0.10
`), (err) => {
match(err.message, new RegExp("/add_change_set/0/frames/0 must have required property 'version'"));
return true;
})
})

it('should require frames to specify an valid action', async (t) => {
await rejects(() => apply(t.name, `
add change set:
- effective from: 2020-04-05T00:00:00.000Z
frames:
- entity: VAT Rate
version: 1
data:
- type: standard
rate: 0.10
`), (err) => {
match(err.message, new RegExp("/add_change_set/0/frames/0 must have required property 'action'"));
return true;
})

await rejects(() => apply(t.name, `
add change set:
- effective from: 2020-04-05T00:00:00.000Z
frames:
- entity: VAT Rate
version: 1
action: MEH
data:
- type: standard
rate: 0.10
`), (err) => {
match(err.message, new RegExp("/add_change_set/0/frames/0/action must be equal to one of the allowed values: POST, DELETE"));
return true;
})
})

it('should require frame data to specify at least one value', async (t) => {
await rejects(() => apply(t.name, `
add change set:
- effective from: 2020-04-05T00:00:00.000Z
frames:
- entity: VAT Rate
version: 1
action: POST
`), (err) => {
match(err.message, new RegExp("/add_change_set/0/frames/0 must have required property 'data'"));
return true;
})
})

it('should require frame data to specify at least one value', async (t) => {
await rejects(() => apply(t.name, `
add change set:
- effective from: 2020-04-05T00:00:00.000Z
frames:
- entity: VAT Rate
version: 1
action: POST
data:
`), (err) => {
match(err.message, new RegExp("/add_change_set/0/frames/0/data must be an array"));
return true;
})
})
})

describe('Aggregates', () => {
it('should aggregate data frames up to the specified change set', async (t) => {
await apply(t.name, `
Expand Down

0 comments on commit 8b4632c

Please sign in to comment.