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

Allow for returning roomId in onAliasQuery #288

Merged
merged 2 commits into from
Dec 2, 2020

Conversation

MadLittleMods
Copy link
Contributor

@MadLittleMods MadLittleMods commented Dec 2, 2020

Allow for returning roomId in onAliasQuery.

Instead of needing to return creationOpts, you can now create the room yourself and return the new roomId you made.


MR for context where we want this feature: https://gitlab.com/gitterHQ/webapp/-/merge_requests/2088

As discussed in https://matrix.to/#/!ViClwbclMrgQwyPuvH:matrix.org/$VgYNMvbNXI8wjhwD5y9kI_vuQbgWgfF1-akf2VnAaNQ?via=half-shot.uk&via=matrix.org&via=tchncs.de

Dev notes

npm run test -- spec/integ/bridge.spec.js

expect(clients["bot"].createRoom).not.toHaveBeenCalled();

const room = await bridge.getRoomStore().getMatrixRoom("!abc123:bar");
expect(room).toBeDefined();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This bottom part to assert the room is just taken from the tests below but I am pretty confused about it testing anything.

If you actually debug this, room is null and the test seems to support both cases so that is why it passes. Seems to be a problem with all of the tests here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Feels like you need to await onAliasQuery to ensure that the promises all run here? This might be a bug with the other tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

With:

            bridgeCtrl.onAliasQuery.and.returnValue({ roomId: "!abc123:bar" });
            await bridge.run(101, {}, appService);

            await appService.onAliasQuery("#foo:bar");

            expect(clients["bot"].createRoom).not.toHaveBeenCalled();

            const room = await bridge.getRoomStore().getMatrixRoom("!abc123:bar");
            expect(room).toBeDefined();
            expect(room.getId()).toEqual("!abc123:bar");

it seems to pass :)

Copy link
Contributor Author

@MadLittleMods MadLittleMods Dec 2, 2020

Choose a reason for hiding this comment

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

Thanks for spotting that! Just copy pasting everything from the other tests. We should fix those other tests up too in another PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created #289 to fix the other tests

@@ -187,6 +187,22 @@ describe("Bridge", function() {
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am seeing linting and test errors for something I didn't change. Am I doing something wrong?

https://buildkite.com/matrix-dot-org/matrix-appservice-bridge/builds/411#dad87f0f-d7c1-4a2c-a9e6-8e9ea816d86d

src/components/client-factory.ts:128:62 - error TS2731: Implicit conversion of a 'symbol' to a 'string' will fail at runtime. Consider wrapping this expression in 'String(...)'.
--
  |  
  | 128                 const loggerInstance = logging.get(`js-sdk:${loggerName}`);

Copy link
Contributor

Choose a reason for hiding this comment

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

This is #286

src/bridge.ts Outdated Show resolved Hide resolved
expect(clients["bot"].createRoom).not.toHaveBeenCalled();

const room = await bridge.getRoomStore().getMatrixRoom("!abc123:bar");
expect(room).toBeDefined();
Copy link
Contributor

Choose a reason for hiding this comment

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

Feels like you need to await onAliasQuery to ensure that the promises all run here? This might be a bug with the other tests.

@@ -187,6 +187,22 @@ describe("Bridge", function() {
});
});

it("should not create a room if roomId is returned from the function but should still store it",
async function(done) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you need done here. Some tests use it because they were written long before async was a thing.


const room = await bridge.getRoomStore().getMatrixRoom("!abc123:bar");
expect(room).toBeDefined();
if (!room) { done(); return; }
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm concerned about this, if you await onAliasQuery you shouldn't need this?

expect(clients["bot"].createRoom).not.toHaveBeenCalled();

const room = await bridge.getRoomStore().getMatrixRoom("!abc123:bar");
expect(room).toBeDefined();
Copy link
Contributor

Choose a reason for hiding this comment

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

With:

            bridgeCtrl.onAliasQuery.and.returnValue({ roomId: "!abc123:bar" });
            await bridge.run(101, {}, appService);

            await appService.onAliasQuery("#foo:bar");

            expect(clients["bot"].createRoom).not.toHaveBeenCalled();

            const room = await bridge.getRoomStore().getMatrixRoom("!abc123:bar");
            expect(room).toBeDefined();
            expect(room.getId()).toEqual("!abc123:bar");

it seems to pass :)

Instead of needing to return `creationOpts`, you can now create the room yourself
and return the new `roomId` you made.

MR for context where we want this feature: https://gitlab.com/gitterHQ/webapp/-/merge_requests/2088
@Half-Shot Half-Shot merged commit 5f0fdf1 into develop Dec 2, 2020
MadLittleMods added a commit that referenced this pull request Dec 2, 2020
MadLittleMods added a commit that referenced this pull request Dec 2, 2020
@Half-Shot Half-Shot deleted the onAliasQuery-return-roomId branch May 2, 2023 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants