generator-jhipster
generator-jhipster copied to clipboard
Authority relationship
enables relationships to 'Authority' in entity-server and ensures using the correct fields in generated files
fix #11062
-
Please make sure the below checklist is followed for Pull Requests.
-
[ ] All continuous integration tests are green
-
[ ] Tests are added where necessary
-
[ ] Documentation is added/updated where necessary
-
[ ] Coding Rules & Commit Guidelines as per our CONTRIBUTING.md document are followed
hey @jhipster/developers I have finished (IMHO) this feature and I was testing it against this JDL:
entity Alpha
entity Beta
entity Gamma
relationship OneToOne {
Alpha{authority(name)} to Authority
}
relationship ManyToOne {
Beta{authority(name)} to Authority
}
relationship ManyToMany {
Gamma{authority(name)} to Authority
}
and this works fine...
So I wanted to add some meaningful test to cover it, and I'm struggling with the yeoman helper and asking for some hint to make this work:
in entity.spec.js
I added a new test case with the following code:
describe('with authority as relationship', () => {
before(done => {
helpers
.run(require.resolve('../generators/entity'))
.inTmpDir(dir => {
fse.copySync(path.join(__dirname, '../test/templates/default-ng2'), dir);
})
.withArguments(['foo'])
.withPrompts({
fieldAdd: false,
relationshipAdd: true,
otherEntityName: 'authority',
relationshipName: 'authority',
relationshipType: 'many-to-one',
ownerSide: true,
otherEntityRelationshipName: 'foo',
otherEntityField: 'name'
})
.withPrompts({
relationshipAdd: false,
dto: 'no',
service: 'no',
pagination: 'no'
})
.on('end', done);
});
it('creates expected default files', () => {
assert.file(expectedFiles.server);
assert.file(expectedFiles.clientNg2);
assert.file(expectedFiles.gatling);
assert.file(expectedFiles.fakeData);
});
it('creates correct entity files for authority', () => {
// entity related files exist
assert.file(`${CLIENT_MAIN_SRC_DIR}app/entities/foo/foo.module.ts`);
assert.file(`${CLIENT_MAIN_SRC_DIR}app/entities/foo/foo.component.html`);
assert.file('.jhipster/Foo.json');
assert.fileContent('.jhipster/Foo.json', 'many-to-one');
assert.fileContent('.jhipster/Foo.json', {
relationships: [
{
relationshipType: 'many-to-one',
otherEntityName: 'authority',
otherEntityRelationshipName: 'foo',
relationshipName: 'authority',
otherEntityField: 'name'
}
]
});
assert.fileContent(
`${CLIENT_MAIN_SRC_DIR}app/entities/foo/foo.component.html`,
"<a [routerLink]=\"['/authority', foo.authority?.name, 'view']\" >{{ foo.authority?.name }}</a>"
);
});
});
I try to generate an entity with a relationship. From my dumb perspective, this should be the correct usage of Yeomans test helper to answer the prompts. However, this ends up with an entity without a relationship. What am I doing wrong here?
push, I still need some help with the test, then this PR could be merged
I'll try to see what's wrong this morning
thanks... I dunno what's wrong with the usage of the helper...and it's quite complex because the relationship question is a repeating one....if that's not possible, I'll try to define a .yo-rc.json
and entity JSONs and do it this way
@xetys it may be easier indeed
@xetys FYI... this PR has conflicts that need to be resolved.
@mraible thx...I didn't forget this one
now I fixed the test as well, and all stuff mentioned in Review (hopefully)
May this PR finally be closed :pray:
A e2e test is missing too. Add a TestAuthorityRelationship to https://github.com/jhipster/generator-jhipster/tree/master/test-integration/samples/.jhipster.
And insert here: https://github.com/jhipster/generator-jhipster/blob/0e4b8dc74087603bc781ce2d9983251722af0314/test-integration/scripts/11-generate-entities.sh#L117-L118
I think this is the last round.
@xetys have you noticed the failures are related to your PR?
Yeah, it's now related to react. As I have no react experience I'll need some time to figure out how to fix this. Shouldn't be too hard but I'll need a bit of time for this
still failing because oauth2 is an edge case....I see this is one of the nastiest $100 bug bounties in history :D I'll try to fix that one today >.<
still failing because oauth2 is an edge case....I see this is one of the nastiest $100 bug bounties in history :D I'll try to fix that one today >.<
I don’t think it is required, just throw an exception at the generator when you detect oauth2. And blacklist authority from oauth builds, I will think how to do this one.
The only way I could find is to duplicate the sqlfull https://github.com/jhipster/generator-jhipster/blob/d4880e95bf6610894493844d843140b59d0e833b/test-integration/scripts/11-generate-entities.sh#L90 @xetys it will be hard to add oauth2 support?
@xetys Is this something you're still interested in adding? If so, please fix conflicts.
Closing because this PR is stale.
Any news about this? Since https://github.com/jhipster/generator-jhipster/issues/1995 has been closed, I'm thinking to create a custom Authority. If this PR is rejected, then obviously I could do everything manually, but ideally, I would like to design the whole domain with JDL
Closing because this PR has become stale. Please re-open if you're able to rebase.