Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ describe('RovoDevEntitlementChecker', () => {
let mockClientManager: any;
let mockConfig: any;
let mockFeatureGateClient: any;

let mockSiteManager: any;
beforeEach(() => {
mockSiteManager = {
onDidSitesAvailableChange: jest.fn().mockReturnValue({ dispose: jest.fn() }),
};
(Container as any).siteManager = mockSiteManager;
mockAnalyticsClient = {
sendTrackEvent: jest.fn(),
} as any;
Expand All @@ -43,6 +47,7 @@ describe('RovoDevEntitlementChecker', () => {
(Container as any).clientManager = mockClientManager;
(Container as any).config = mockConfig;
(Container as any).featureFlagClient = mockFeatureGateClient;
(Container as any).siteManager = mockSiteManager;
(Logger.debug as jest.Mock).mockImplementation(() => {});
(Logger.error as jest.Mock).mockImplementation(() => {});
(rovoDevEntitlementCheckEvent as jest.Mock).mockResolvedValue({});
Expand Down
19 changes: 16 additions & 3 deletions src/util/rovo-dev-entitlement/rovoDevEntitlementChecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,36 @@ export class RovoDevEntitlementChecker extends Disposable {

private _enabled: boolean;

private _cachedEntitlement: EntitlementResponse | null;

private disposable: Disposable;

constructor(analyticsClient: AnalyticsClient) {
super(() => this._dispose());
this._analyticsClient = analyticsClient;
this._enabled = Container.config.rovodev.showEntitlementNotifications;

this.disposable = Disposable.from(configuration.onDidChange(this.onDidChangeConfiguration, this));
this._cachedEntitlement = null;
this.disposable = Disposable.from(
configuration.onDidChange(this.onDidChangeConfiguration, this),
Container.siteManager.onDidSitesAvailableChange(async () => {
this._cachedEntitlement = null;
}, this),
);
}

private onDidChangeConfiguration(e: ConfigurationChangeEvent) {
if (configuration.changed(e, 'rovodev.showEntitlementNotifications')) {
this._enabled = Container.config.rovodev.showEntitlementNotifications;
this._cachedEntitlement = null;
}
}

public async checkEntitlement(): Promise<EntitlementResponse> {
try {
if (this._cachedEntitlement) {
Logger.debug(`Cached entitlement response: ${this._cachedEntitlement.type}`);
return this._cachedEntitlement;
}
const credentials = await Container.clientManager.getCloudPrimarySite();

if (!credentials) {
Expand Down Expand Up @@ -96,10 +108,11 @@ export class RovoDevEntitlementChecker extends Disposable {
this._analyticsClient.sendTrackEvent(e);
});

return {
this._cachedEntitlement = {
isEntitled: true,
type: value.trim() as RovoDevEntitlementType,
};
return this._cachedEntitlement;
} catch (err) {
Logger.error(err, 'Unable to check Rovo Dev entitlement');
const errType: string =
Expand Down
Loading