chore: fix ContentType usage (#2353)

* chore: fix ContentType usage

* chore: fix specs
This commit is contained in:
Karol Sójko
2023-07-12 13:53:29 +02:00
committed by GitHub
parent d057cdff84
commit 325737bfbd
247 changed files with 1092 additions and 1060 deletions

View File

@@ -2,8 +2,7 @@ import { ItemInterface, SNComponent, SNFeatureRepo } from '@standardnotes/models
import { SNSyncService } from '../Sync/SyncService'
import { SettingName } from '@standardnotes/settings'
import { SNFeaturesService } from '@Lib/Services/Features'
import { ContentType } from '@standardnotes/common'
import { RoleName } from '@standardnotes/domain-core'
import { ContentType, RoleName } from '@standardnotes/domain-core'
import { FeatureDescription, FeatureIdentifier, GetFeatures } from '@standardnotes/features'
import { SNWebSocketsService } from '../Api/WebsocketsService'
import { SNSettingsService } from '../Settings'
@@ -157,7 +156,7 @@ describe('featuresService', () => {
{
identifier: FeatureIdentifier.PlusEditor,
expires_at: tomorrow_server,
content_type: ContentType.Component,
content_type: ContentType.TYPES.Component,
},
]
@@ -307,10 +306,10 @@ describe('featuresService', () => {
expect(mutator.createItem).toHaveBeenCalledTimes(2)
expect(mutator.createItem).toHaveBeenCalledWith(
ContentType.Theme,
ContentType.TYPES.Theme,
expect.objectContaining({
package_info: expect.objectContaining({
content_type: ContentType.Theme,
content_type: ContentType.TYPES.Theme,
expires_at: tomorrow_client,
identifier: FeatureIdentifier.MidnightTheme,
}),
@@ -318,10 +317,10 @@ describe('featuresService', () => {
true,
)
expect(mutator.createItem).toHaveBeenCalledWith(
ContentType.Component,
ContentType.TYPES.Component,
expect.objectContaining({
package_info: expect.objectContaining({
content_type: ContentType.Component,
content_type: ContentType.TYPES.Component,
expires_at: tomorrow_client,
identifier: FeatureIdentifier.PlusEditor,
}),
@@ -333,7 +332,7 @@ describe('featuresService', () => {
it('if item for a feature exists updates its content', async () => {
const existingItem = new SNComponent({
uuid: '789',
content_type: ContentType.Component,
content_type: ContentType.TYPES.Component,
content: {
package_info: {
identifier: FeatureIdentifier.PlusEditor,
@@ -379,10 +378,10 @@ describe('featuresService', () => {
await featuresService.fetchFeatures('123', didChangeRoles)
expect(mutator.createItem).toHaveBeenCalledWith(
ContentType.Component,
ContentType.TYPES.Component,
expect.objectContaining({
package_info: expect.objectContaining({
content_type: ContentType.Component,
content_type: ContentType.TYPES.Component,
expires_at: yesterday_client,
identifier: FeatureIdentifier.PlusEditor,
}),
@@ -394,7 +393,7 @@ describe('featuresService', () => {
it('deletes items for expired themes', async () => {
const existingItem = new SNComponent({
uuid: '456',
content_type: ContentType.Theme,
content_type: ContentType.TYPES.Theme,
content: {
package_info: {
identifier: FeatureIdentifier.MidnightTheme,
@@ -498,7 +497,7 @@ describe('featuresService', () => {
it('remote native features should be swapped with compiled version', async () => {
const remoteFeature = {
identifier: FeatureIdentifier.PlusEditor,
content_type: ContentType.Component,
content_type: ContentType.TYPES.Component,
expires_at: tomorrow_server,
} as FeatureDescription
@@ -528,7 +527,7 @@ describe('featuresService', () => {
it('mapRemoteNativeFeatureToItem should throw if called with client controlled feature', async () => {
const clientFeature = {
identifier: FeatureIdentifier.DarkTheme,
content_type: ContentType.Theme,
content_type: ContentType.TYPES.Theme,
clientControlled: true,
} as FeatureDescription
@@ -573,13 +572,13 @@ describe('featuresService', () => {
features = [
{
identifier: FeatureIdentifier.MidnightTheme,
content_type: ContentType.Theme,
content_type: ContentType.TYPES.Theme,
expires_at: tomorrow_server,
role_name: RoleName.NAMES.PlusUser,
},
{
identifier: FeatureIdentifier.PlusEditor,
content_type: ContentType.Component,
content_type: ContentType.TYPES.Component,
expires_at: expiredDate,
role_name: RoleName.NAMES.ProUser,
},
@@ -617,14 +616,14 @@ describe('featuresService', () => {
const themeFeature = {
identifier: 'third-party-theme' as FeatureIdentifier,
content_type: ContentType.Theme,
content_type: ContentType.TYPES.Theme,
expires_at: tomorrow_server,
role_name: RoleName.NAMES.CoreUser,
}
const editorFeature = {
identifier: 'third-party-editor' as FeatureIdentifier,
content_type: ContentType.Component,
content_type: ContentType.TYPES.Component,
expires_at: expiredDate,
role_name: RoleName.NAMES.PlusUser,
}
@@ -636,7 +635,7 @@ describe('featuresService', () => {
itemManager.getDisplayableComponents = jest.fn().mockReturnValue([
new SNComponent({
uuid: '123',
content_type: ContentType.Theme,
content_type: ContentType.TYPES.Theme,
content: {
valid_until: themeFeature.expires_at,
package_info: {
@@ -646,7 +645,7 @@ describe('featuresService', () => {
} as never),
new SNComponent({
uuid: '456',
content_type: ContentType.Component,
content_type: ContentType.TYPES.Component,
content: {
valid_until: new Date(editorFeature.expires_at),
package_info: {
@@ -774,7 +773,7 @@ describe('featuresService', () => {
const extensionKey = '129b029707e3470c94a8477a437f9394'
const extensionRepoItem = new SNFeatureRepo({
uuid: '456',
content_type: ContentType.ExtensionRepo,
content_type: ContentType.TYPES.ExtensionRepo,
content: {
url: `https://extensions.standardnotes.org/${extensionKey}`,
},

View File

@@ -8,8 +8,7 @@ import {
isString,
} from '@standardnotes/utils'
import { ClientDisplayableError, isErrorResponse } from '@standardnotes/responses'
import { ContentType } from '@standardnotes/common'
import { RoleName } from '@standardnotes/domain-core'
import { ContentType, RoleName } from '@standardnotes/domain-core'
import { FillItemContent, PayloadEmitSource } from '@standardnotes/models'
import { ItemManager } from '../Items/ItemManager'
import { LEGACY_PROD_EXT_ORIGIN, PROD_OFFLINE_FEATURES_URL } from '../../Hosts'
@@ -96,7 +95,7 @@ export class SNFeaturesService
})
this.removefeatureReposObserver = this.itemManager.addObserver(
ContentType.ExtensionRepo,
ContentType.TYPES.ExtensionRepo,
async ({ changed, inserted, source }) => {
const sources = [
PayloadEmitSource.InitialObserverRegistrationPush,
@@ -119,7 +118,7 @@ export class SNFeaturesService
this.removeSignInObserver = this.userService.addEventObserver((eventName: AccountEvent) => {
if (eventName === AccountEvent.SignedInOrRegistered) {
const featureRepos = this.itemManager.getItems(ContentType.ExtensionRepo) as Models.SNFeatureRepo[]
const featureRepos = this.itemManager.getItems(ContentType.TYPES.ExtensionRepo) as Models.SNFeatureRepo[]
if (!this.apiService.isThirdPartyHostUsed()) {
void this.migrateFeatureRepoToUserSetting(featureRepos)
@@ -179,7 +178,10 @@ export class SNFeaturesService
private async mapClientControlledFeaturesToItems() {
const clientFeatures = FeaturesImports.GetFeatures().filter((feature) => feature.clientControlled)
const currentItems = this.itemManager.getItems<Models.SNComponent>([ContentType.Component, ContentType.Theme])
const currentItems = this.itemManager.getItems<Models.SNComponent>([
ContentType.TYPES.Component,
ContentType.TYPES.Theme,
])
for (const feature of clientFeatures) {
if (!feature.content_type) {
@@ -226,7 +228,7 @@ export class SNFeaturesService
void this.storageService.setValue(StorageKey.ExperimentalFeatures, this.enabledExperimentalFeatures)
const component = this.itemManager
.getItems<Models.SNComponent | Models.SNTheme>([ContentType.Component, ContentType.Theme])
.getItems<Models.SNComponent | Models.SNTheme>([ContentType.TYPES.Component, ContentType.TYPES.Theme])
.find((component) => component.identifier === identifier)
if (!component) {
return
@@ -273,7 +275,7 @@ export class SNFeaturesService
}
const offlineRepo = (await this.mutator.createItem(
ContentType.ExtensionRepo,
ContentType.TYPES.ExtensionRepo,
FillItemContent({
offlineFeaturesUrl: result.featuresUrl,
offlineKey: result.extensionKey,
@@ -289,7 +291,7 @@ export class SNFeaturesService
}
private getOfflineRepo(): Models.SNFeatureRepo | undefined {
const repos = this.itemManager.getItems(ContentType.ExtensionRepo) as Models.SNFeatureRepo[]
const repos = this.itemManager.getItems(ContentType.TYPES.ExtensionRepo) as Models.SNFeatureRepo[]
return repos.filter((repo) => repo.migratedToOfflineEntitlements)[0]
}
@@ -638,7 +640,10 @@ export class SNFeaturesService
}
private async mapRemoteNativeFeaturesToItems(features: FeaturesImports.FeatureDescription[]): Promise<void> {
const currentItems = this.itemManager.getItems<Models.SNComponent>([ContentType.Component, ContentType.Theme])
const currentItems = this.itemManager.getItems<Models.SNComponent>([
ContentType.TYPES.Component,
ContentType.TYPES.Theme,
])
const itemsToDelete: Models.SNComponent[] = []
let hasChanges = false
@@ -715,7 +720,7 @@ export class SNFeaturesService
} else {
resultingItem = existingItem
}
} else if (!expired || feature.content_type === ContentType.Component) {
} else if (!expired || feature.content_type === ContentType.TYPES.Component) {
resultingItem = (await this.mutator.createItem(
feature.content_type,
this.componentContentForNativeFeatureDescription(feature),
@@ -725,7 +730,7 @@ export class SNFeaturesService
}
if (expired && resultingItem) {
if (feature.content_type !== ContentType.Component) {
if (feature.content_type !== ContentType.TYPES.Component) {
itemsToDelete.push(resultingItem)
hasChanges = true
}
@@ -786,10 +791,10 @@ export class SNFeaturesService
}
const isValidContentType = [
ContentType.Component,
ContentType.Theme,
ContentType.ActionsExtension,
ContentType.ExtensionRepo,
ContentType.TYPES.Component,
ContentType.TYPES.Theme,
ContentType.TYPES.ActionsExtension,
ContentType.TYPES.ExtensionRepo,
].includes(rawFeature.content_type)
if (!isValidContentType) {