@defra/lis-infra-ui-services 0.17.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defra/lis-infra-ui-services",
3
- "version": "0.17.0",
3
+ "version": "0.18.0",
4
4
  "description": "UI-Services shared definitions for the livestock taxonomy topology.",
5
5
  "main": "src/index.js",
6
6
  "repository": {
@@ -14,7 +14,7 @@ export function buildPrimaryNavigation({ request, basePath = '' }) {
14
14
  href: '/profile',
15
15
  current: request?.path === '/profile' && !currentSpecies?.id
16
16
  }
17
- const permittedSpecies = request?.app?.authorizedSpecies
17
+ const permittedSpecies = request?.auth?.credentials?.authorizedSpecies
18
18
 
19
19
  if (!Array.isArray(permittedSpecies) || permittedSpecies.length === 0) {
20
20
  return []
@@ -7,11 +7,13 @@ test('buildPrimaryNavigation renders species already authorized by the host', ()
7
7
  const navigation = buildPrimaryNavigation({
8
8
  request: {
9
9
  path: '/',
10
- app: {
11
- authorizedSpecies: [
12
- { id: 'cattle', label: 'Cattle' },
13
- { id: 'sheep', label: 'Sheep' }
14
- ]
10
+ auth: {
11
+ credentials: {
12
+ authorizedSpecies: [
13
+ { id: 'cattle', label: 'Cattle' },
14
+ { id: 'sheep', label: 'Sheep' }
15
+ ]
16
+ }
15
17
  }
16
18
  }
17
19
  })
@@ -34,8 +36,10 @@ test('buildPrimaryNavigation marks the profile item as current on the profile ro
34
36
  const navigation = buildPrimaryNavigation({
35
37
  request: {
36
38
  path: '/profile',
37
- app: {
38
- authorizedSpecies: [{ id: 'cattle', label: 'Cattle' }]
39
+ auth: {
40
+ credentials: {
41
+ authorizedSpecies: [{ id: 'cattle', label: 'Cattle' }]
42
+ }
39
43
  }
40
44
  }
41
45
  })
@@ -43,3 +47,16 @@ test('buildPrimaryNavigation marks the profile item as current on the profile ro
43
47
  assert.equal(navigation.at(-1)?.text, 'Profile')
44
48
  assert.equal(navigation.at(-1)?.current, true)
45
49
  })
50
+
51
+ test('buildPrimaryNavigation ignores the legacy request.app.authorizedSpecies', () => {
52
+ const navigation = buildPrimaryNavigation({
53
+ request: {
54
+ path: '/',
55
+ app: {
56
+ authorizedSpecies: [{ id: 'cattle', label: 'Cattle' }]
57
+ }
58
+ }
59
+ })
60
+
61
+ assert.deepEqual(navigation, [])
62
+ })
@@ -46,7 +46,7 @@ export function createNunjucksContextBuilder({
46
46
  serviceUrl: '/',
47
47
  breadcrumbs: [],
48
48
  navigation: buildNavigation(request),
49
- isSignedIn: Boolean(request?.app?.hubAuth),
49
+ isSignedIn: Boolean(request?.auth?.credentials?.user),
50
50
  logoutUrl: '/signout',
51
51
  getAssetPath(asset) {
52
52
  const viteAssetPath = viteManifest?.[asset]?.file
@@ -165,3 +165,45 @@ test('createNunjucksContextBuilder always sets serviceUrl to the hub root even w
165
165
  assert.equal(context.assetPath, '/cattle/register/public/assets')
166
166
  assert.deepEqual(loggerMessages, [])
167
167
  })
168
+
169
+ function createSignedInContextBuilder() {
170
+ return createNunjucksContextBuilder({
171
+ config: createConfig(),
172
+ buildNavigation: () => [],
173
+ getRequestBasePath: () => '',
174
+ logger: { error: () => undefined },
175
+ readFileSync: () => '{}'
176
+ })
177
+ }
178
+
179
+ test('createNunjucksContextBuilder marks the user signed in from the auth credentials', () => {
180
+ const context = createSignedInContextBuilder()({
181
+ headers: {},
182
+ path: '/',
183
+ auth: { credentials: { user: { sub: 'user-1' } } },
184
+ app: {}
185
+ })
186
+
187
+ assert.equal(context.isSignedIn, true)
188
+ })
189
+
190
+ test('createNunjucksContextBuilder ignores the legacy request.app.hubAuth', () => {
191
+ const context = createSignedInContextBuilder()({
192
+ headers: {},
193
+ path: '/',
194
+ app: { hubAuth: { sub: 'user-1' } }
195
+ })
196
+
197
+ assert.equal(context.isSignedIn, false)
198
+ })
199
+
200
+ test('createNunjucksContextBuilder marks the user signed out without credentials', () => {
201
+ const context = createSignedInContextBuilder()({
202
+ headers: {},
203
+ path: '/',
204
+ auth: { credentials: null },
205
+ app: {}
206
+ })
207
+
208
+ assert.equal(context.isSignedIn, false)
209
+ })