generator-jhipster icon indicating copy to clipboard operation
generator-jhipster copied to clipboard

Authority relationship

Open xetys opened this issue 5 years ago • 17 comments

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

xetys avatar Jan 21 '20 23:01 xetys

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?

xetys avatar Feb 25 '20 09:02 xetys

push, I still need some help with the test, then this PR could be merged

xetys avatar Mar 10 '20 08:03 xetys

I'll try to see what's wrong this morning

MathieuAA avatar Mar 10 '20 08:03 MathieuAA

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 avatar Mar 10 '20 09:03 xetys

@xetys it may be easier indeed

MathieuAA avatar Mar 10 '20 09:03 MathieuAA

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Apr 20 '20 12:04 CLAassistant

@xetys FYI... this PR has conflicts that need to be resolved.

mraible avatar Apr 27 '20 16:04 mraible

@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:

xetys avatar May 18 '20 19:05 xetys

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.

mshima avatar May 19 '20 14:05 mshima

@xetys have you noticed the failures are related to your PR?

mshima avatar May 25 '20 12:05 mshima

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

xetys avatar May 25 '20 12:05 xetys

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 >.<

xetys avatar Jun 11 '20 10:06 xetys

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.

mshima avatar Jun 11 '20 11:06 mshima

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?

mshima avatar Jun 15 '20 18:06 mshima

@xetys Is this something you're still interested in adding? If so, please fix conflicts.

mraible avatar Dec 29 '20 23:12 mraible

Closing because this PR is stale.

mraible avatar Jan 29 '21 01:01 mraible

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

Rapster avatar Mar 10 '22 18:03 Rapster

Closing because this PR has become stale. Please re-open if you're able to rebase.

mraible avatar Aug 17 '22 08:08 mraible