Skip to content

Commit

Permalink
feat: refresh self protocols on team refresh (#15897)
Browse files Browse the repository at this point in the history
* feat: refresh self protocols after team is refreshed periodically

* test: refresh self protocols on team refresh
  • Loading branch information
PatrykBuniX authored Sep 28, 2023
1 parent 733c306 commit 88f3411
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/script/self/SelfRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,25 @@ describe('SelfRepository', () => {
expect(selfRepository.refreshSelfSupportedProtocols).toHaveBeenCalled();
});

it('refreshes self supported protocols on team refresh', async () => {
const selfRepository = await testFactory.exposeSelfActors();

const selfUser = selfRepository['userState'].self()!;

const initialProtocols = [ConversationProtocol.PROTEUS];
selfUser.supportedProtocols(initialProtocols);

const evaluatedProtocols = [ConversationProtocol.PROTEUS, ConversationProtocol.MLS];

jest.spyOn(selfRepository, 'evaluateSelfSupportedProtocols').mockResolvedValueOnce(evaluatedProtocols);
jest.spyOn(selfRepository['selfService'], 'putSupportedProtocols');

await act(async () => selfRepository['teamRepository'].emit('teamRefreshed'));

expect(selfUser.supportedProtocols()).toEqual(evaluatedProtocols);
expect(selfRepository['selfService'].putSupportedProtocols).toHaveBeenCalledWith(evaluatedProtocols);
});

it('refreshes self supported protocols after mls feature is enabled', async () => {
const selfRepository = await testFactory.exposeSelfActors();

Expand Down
1 change: 1 addition & 0 deletions src/script/self/SelfRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export class SelfRepository {
// It's possible that they have removed proteus client, and now all their clients are mls-capable.
amplify.subscribe(WebAppEvents.CLIENT.REMOVE, this.refreshSelfSupportedProtocols);

teamRepository.on('teamRefreshed', this.refreshSelfSupportedProtocols);
teamRepository.on('featureUpdated', ({event, prevFeatureList}) => {
if (event.name === FEATURE_KEY.MLS) {
void this.handleMLSFeatureUpdate(event.data, prevFeatureList?.[FEATURE_KEY.MLS]);
Expand Down
2 changes: 2 additions & 0 deletions src/script/team/TeamRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ type Events = {
prevFeatureList?: FeatureList;
event: TeamFeatureConfigurationUpdateEvent;
};
teamRefreshed: void;
};

export class TeamRepository extends TypedEventEmitter<Events> {
Expand Down Expand Up @@ -156,6 +157,7 @@ export class TeamRepository extends TypedEventEmitter<Events> {
try {
await this.getTeam();
await this.updateFeatureConfig();
this.emit('teamRefreshed');
} catch (error) {
this.logger.error(error);
}
Expand Down

0 comments on commit 88f3411

Please sign in to comment.