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

feat: lb3 migration tests for models customized with db metadata #4710

Merged
merged 1 commit into from
Feb 25, 2020
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
7 changes: 0 additions & 7 deletions docs/site/Importing-LB3-models.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@ your project. It will help us to better prioritize which limitations to remove
first.
" %}

### Connector-specific metadata in property definitions is not imported

_The tracking GitHub issue:
[loopback-next#3810](https://github.com/strongloop/loopback-next/issues/3810)_

Workaround: Add this metadata manually to the generated file.

### Nested properties are not upgraded

_The tracking GitHub issue:
Expand Down
68 changes: 68 additions & 0 deletions packages/cli/test/unit/import-lb3-model/migrate-model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,74 @@ describe('importLb3ModelDefinition', () => {
});
});

context('model properties with db settings', () => {
let modelData;

const STRING_PROPERTY = {
type: 'String',
required: false,
length: 25,
precision: null,
scale: null,
postgresql: {
columnName: 'name',
dataType: 'character varying',
dataLength: 25,
dataPrecision: null,
dataScale: null,
nullable: 'YES',
},
};

const NUMERIC_PROPERTY = {
type: 'Number',
required: false,
length: null,
precision: 64,
scale: 0,
postgresql: {
columnName: 'count',
dataType: 'bigint',
dataLength: null,
dataPrecision: 64,
dataScale: 0,
nullable: 'YES',
},
};

before(function modelWithCustomDbSettings() {
const properties = {
name: STRING_PROPERTY,
count: NUMERIC_PROPERTY,
};
const MyModel = givenLb3Model('MyModel', properties, {});
modelData = importLb3ModelDefinition(MyModel, log);
});

it('connector metadata is migrated for string property', () => {
expect(modelData.properties)
.to.have.property('name')
.deepEqual({
type: `'string'`,
tsType: 'string',
length: 25,
postgresql: `{columnName: 'name', dataType: 'character varying', dataLength: 25, dataPrecision: null, dataScale: null, nullable: 'YES'}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

@deepakrkris I'm just wondering why a string and not an object passed here. Why is this not like this?:

{
  type: `'string'`,
  tsType: 'string',
  length: 25,
  postgresql: {
    columnName: 'name',
    dataType: 'character varying',
    dataLength: 25,
    dataPrecision: null,
    dataScale: null,
    nullable: 'YES'
  },
},

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@derdeka thanks for the review. The unit test is for the function importLb3ModelDefinition it returns json values as strings. But the template generator takes care of converting into json objects.

});
});

it('connector metadata is migrated for numeric property', () => {
expect(modelData.properties)
.to.have.property('count')
.deepEqual({
type: `'number'`,
tsType: 'number',
precision: 64,
scale: 0,
postgresql: `{columnName: 'count', dataType: 'bigint', dataLength: null, dataPrecision: 64, dataScale: 0, nullable: 'YES'}`,
});
});
});

context('array properties', () => {
it('correctly converts short-hand definition', () => {
const MyModel = givenLb3Model('MyModel', {
Expand Down