all files / tests/dummy/app/utils/ dynamic-segment-resolver.js

92.31% Statements 12/13
83.33% Branches 5/6
100% Functions 1/1
90.91% Lines 10/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26                    28× 80× 20× 20× 20× 20× 160×            
import fetch from 'ember-network/fetch';
 
/* eslint-disable */
export default function dynamicSegmentResolver(dynamicSegmentKey, allSegments, otherDynamicSegments) {
 
  /**
   * Uncomment the line below and open localhost:4200/sitemap.txt on your browser.
   * You will see what parameters are passed to this function in the console.
   */
  // console.log('dynamicSegmentResolver:', dynamicSegmentKey, allSegments, otherDynamicSegments);
 
  if (dynamicSegmentKey === 'user_id') {
    return fetch('https://jsonplaceholder.typicode.com/users')
      .then(response => response.json())
      .then(users => users.map(user => user.id));
  } else Eif (dynamicSegmentKey === 'photo_id' && otherDynamicSegments.user_id) {
    return fetch(`https://jsonplaceholder.typicode.com/users/${otherDynamicSegments.user_id}/photos`)
      .then(response => response.json())
      .then(photos => photos.slice(0, 8))
      .then(photos => photos.map(photo => photo.id));
  }
 
  return [];
}