Skip to content

Commit

Permalink
✅ Add dynamic schema test with a specific name
Browse files Browse the repository at this point in the history
  • Loading branch information
skerit committed Mar 23, 2024
1 parent 7e77b3b commit be34724
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
34 changes: 33 additions & 1 deletion test/04-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,18 @@ describe('Field.Schema', function() {
*/
BookWithEnumSchema.setMethod(async function resolveRemoteSchemaRequest(external_field, our_field_name, our_field_value, schema_path) {

console.log('Getting', external_field, our_field_name, our_field_value, schema_path);
// The schema by default is `schema`, unless it is otherwise
// specified in the external field.
// This way, we can have multiple fields that request different schemas
if (schema_path == 'other_schema') {
let schema = alchemy.createSchema();
schema.addField('other_property', 'String');
return schema;
}

if (schema_path != 'schema') {
return;
}

let doc = await this.findByPk(our_field_value);

Expand All @@ -1228,6 +1239,10 @@ describe('Field.Schema', function() {
schema: 'book_with_enum_schema_id'
});

this.addField('other_settings', 'Schema', {
schema: 'book_with_enum_schema_id.other_schema',
});

constitute_pledge.resolve();
});

Expand Down Expand Up @@ -1265,6 +1280,12 @@ describe('Field.Schema', function() {
year: 1986,
};

meta_doc.other_settings = {
other_property: 'other_value',
year: 1986,
goodreads_rating: 4.7,
};

await meta_doc.save();

assert.strictEqual(
Expand All @@ -1285,5 +1306,16 @@ describe('Field.Schema', function() {
'The `year` field should not have been saved, it was not part of the schema'
);

assert.strictEqual(
meta_doc.other_settings.other_property,
'other_value',
'The `other_settings` field should have also been saved'
);

assert.strictEqual(
meta_doc.other_settings.year,
undefined,
'The `year` field in the `other_settings` field should not have been saved, it was not part of the schema'
);
});
});
4 changes: 4 additions & 0 deletions test/10-behaviour.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ describe('RevisionBehaviour', function() {
assert.strictEqual(to_revert.age, 5);
assert.strictEqual(to_revert.__r, 2);

// @TODO: Saving revisions happens in the background,
// so sometimes this revert might come too soon!
await Pledge.after(5);

// Revert 2 versions
await to_revert.revert(2);

Expand Down

0 comments on commit be34724

Please sign in to comment.