All files / src/components getOrganizationLinks.js

90% Statements 27/30
78.57% Branches 11/14
100% Functions 5/5
89.66% Lines 26/29

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54        61x 46x 46x 46x 125x 46x 43x 43x 43x 43x     46x     61x 3x     3x       61x 3x 3x               61x 46x     46x 3x 3x     46x 3x 3x     46x    
/* eslint-disable no-console */
 
import { getOrgId } from "./getOrgId.js";
 
const getGithubInfo = (organization) => {
  const githubInfo = { imageUrl: null, organizationUrl: null };
  const { links } = organization;
  Eif (links) {
    const githubLink = links.find(link => link.link_type === 'GitHub')
    if (githubLink) {
      const id = getOrgId(githubLink.url);
      const imageUrl = `https://avatars1.githubusercontent.com/u/${id}?s=100&v=4`;
      githubInfo.imageUrl = imageUrl;
      githubInfo.organizationUrl = githubLink.url;
    }
  }
  return githubInfo;
}
 
const getImageFromOrg = (organization) => {
  Iif (organization.image_url) {
    return organization.image_url;
  } else {
    return null;
  }
}
 
const getLinksFromOrg = (organization) => {
  Eif (organization.links && organization.links.length) {
    return organization.links[0].url;
  } else {
    // no links, either from github, or on organization object
    console.log(`No links available for ${organization.name}`);
    return null;
  }
}
 
export const getOrganizationLinks = (organization) => {
  const thumbnailInfo = getGithubInfo(organization);
 
  // check for empty results from getGithubInfo
  if (!thumbnailInfo.imageUrl) {
    console.log(`No GitHub image available for ${organization.name}`);
    thumbnailInfo.imageUrl = getImageFromOrg(organization);
  }
 
  if (!thumbnailInfo.organizationUrl) {
    console.log(`No GitHub URL available for ${organization.name}`);
    thumbnailInfo.organizationUrl = getLinksFromOrg(organization);
  }
 
  return thumbnailInfo;
};