Skip to content

Commit 6439571

Browse files
feat(orgs): add selector to determine if org is an IOx org (#6153)
1 parent c2a6347 commit 6439571

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import {isOrgIOx} from 'src/organizations/selectors'
2+
3+
let fakeState: any = {}
4+
5+
describe('determining if an org is an IOx org', () => {
6+
beforeEach(() => {
7+
fakeState = {
8+
resources: {
9+
orgs: {
10+
byID: {
11+
'9c5955fc99a60b8f': {
12+
links: {
13+
buckets: '/api/v2/buckets?org=dev',
14+
dashboards: '/api/v2/dashboards?org=dev',
15+
labels: '/api/v2/orgs/9c5955fc99a60b8f/labels',
16+
limits: '/api/v2/orgs/9c5955fc99a60b8f/limits',
17+
logs: '/api/v2/orgs/9c5955fc99a60b8f/logs',
18+
members: '/api/v2/orgs/9c5955fc99a60b8f/members',
19+
owners: '/api/v2/orgs/9c5955fc99a60b8f/owners',
20+
secrets: '/api/v2/orgs/9c5955fc99a60b8f/secrets',
21+
self: '/api/v2/orgs/9c5955fc99a60b8f',
22+
tasks: '/api/v2/tasks?org=dev',
23+
},
24+
id: '9c5955fc99a60b8f',
25+
name: 'dev',
26+
description: '',
27+
defaultStorageType: 'tsm',
28+
createdAt: '2022-10-24T17:06:47.427700345Z',
29+
updatedAt: '2022-10-24T17:06:47.427700533Z',
30+
},
31+
},
32+
allIDs: ['9c5955fc99a60b8f'],
33+
status: 'Done',
34+
org: {
35+
links: {
36+
buckets: '/api/v2/buckets?org=dev',
37+
dashboards: '/api/v2/dashboards?org=dev',
38+
labels: '/api/v2/orgs/9c5955fc99a60b8f/labels',
39+
limits: '/api/v2/orgs/9c5955fc99a60b8f/limits',
40+
logs: '/api/v2/orgs/9c5955fc99a60b8f/logs',
41+
members: '/api/v2/orgs/9c5955fc99a60b8f/members',
42+
owners: '/api/v2/orgs/9c5955fc99a60b8f/owners',
43+
secrets: '/api/v2/orgs/9c5955fc99a60b8f/secrets',
44+
self: '/api/v2/orgs/9c5955fc99a60b8f',
45+
tasks: '/api/v2/tasks?org=dev',
46+
},
47+
id: '9c5955fc99a60b8f',
48+
name: 'dev',
49+
description: '',
50+
defaultStorageType: 'tsm',
51+
createdAt: '2022-10-24T17:06:47.427700345Z',
52+
updatedAt: '2022-10-24T17:06:47.427700533Z',
53+
},
54+
},
55+
},
56+
}
57+
})
58+
it('returns false when the defaultStorageType is tsm', () => {
59+
expect(isOrgIOx(fakeState)).toBe(false)
60+
})
61+
62+
it('returns false when the defaultStorageType is an empty string', () => {
63+
fakeState.resources.orgs.org.defaultStorageType = ''
64+
expect(isOrgIOx(fakeState)).toBe(false)
65+
})
66+
67+
it('returns false when the defaultStorageType is null', () => {
68+
fakeState.resources.orgs.org.defaultStorageType = null
69+
expect(isOrgIOx(fakeState)).toBe(false)
70+
})
71+
72+
it('returns false when no storage type is present', () => {
73+
delete fakeState.resources.orgs.org.defaultStorageType
74+
expect(isOrgIOx(fakeState)).toBe(false)
75+
})
76+
77+
it('returns true when the defaultStorageType is iox', () => {
78+
fakeState.resources.orgs.org.defaultStorageType = 'iox'
79+
expect(isOrgIOx(fakeState)).toBe(true)
80+
81+
fakeState.resources.orgs.org.defaultStorageType = 'IoX'
82+
expect(isOrgIOx(fakeState)).toBe(true)
83+
})
84+
})

src/organizations/selectors/index.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@ import {get} from 'lodash'
44
// Types
55
import {AppState, Organization} from 'src/types'
66

7+
interface OrganizationWithStorageType extends Organization {
8+
defaultStorageType?: string
9+
}
10+
11+
export const isOrgIOx = (state: AppState): boolean => {
12+
const org: OrganizationWithStorageType = getOrg(state)
13+
14+
return Boolean(
15+
org &&
16+
org.defaultStorageType &&
17+
org.defaultStorageType.toLowerCase() === 'iox'
18+
)
19+
}
20+
721
export const getOrg = (state: AppState): Organization => {
822
return get(state, 'resources.orgs.org', null)
923
}

0 commit comments

Comments
 (0)