import {
  getAllLabels,
  getLabels,
  hasLabel,
  filterIssuesWithLabels,
} from './labels.js';

describe('getLabels', () => {
  it('returns the labels of an issue', () => {
    const issue = {
      id: 1,
      labels: [
        {
          name: 'bug',
        },
        {
          name: 'feature',
        },
      ],
    };
    expect(getLabels(issue)).toEqual(['bug', 'feature']);
  });
});

describe('getAllLabels', () => {
  it('returns the labels of all issues', () => {
    const issues = [
      {
        id: 1,
        labels: [
          {
            name: 'feature',
          },
        ],
      },
      {
        id: 2,
        labels: [
          {
            name: 'feature',
          },
          {
            name: 'bug',
          },
        ],
      },
      {
        id: 3,
      },
    ];
    expect(getAllLabels(issues)).toEqual(['bug', 'feature']);
  });
});

describe('hasLabel', () => {
  it('returns true if the issue has at least one label in the list', () => {
    const issue = {
      id: 1,
      labels: [
        {
          name: 'feature',
        },
      ],
    };
    expect(hasLabel(['feature'])(issue)).toBe(true);
    expect(hasLabel(['bug'])(issue)).toBe(false);
    expect(hasLabel([])(issue)).toBe(false);
  });
});

describe('filterIssuesWithLabels', () => {
  it('returns only issues with the specified labels', () => {
    const issues = [
      {
        id: 1,
        labels: [
          {
            name: 'feature',
          },
        ],
      },
      {
        id: 2,
        labels: [
          {
            name: 'feature',
          },
          {
            name: 'bug',
          },
        ],
      },
      {
        id: 3,
      },
    ];
    expect(filterIssuesWithLabels(issues, ['bug'])).toEqual([
      {
        id: 2,
        labels: [
          {
            name: 'feature',
          },
          {
            name: 'bug',
          },
        ],
      },
    ]);
  });
});

@@ -96,95 +96,129 @@
 ';%0A%0A
-describe('getLabels', () =%3E %7B%0A  it('returns the labels of an issue', () =%3E
+function makeLabel(labelName) %7B%0A  return %7B%0A    name: labelName,%0A  %7D;%0A%7D%0A%0Afunction makeIssue(labelNames, id = 1)
  %7B%0A
-  
   const 
 issu
@@ -217,153 +217,207 @@
 nst 
-issue = %7B%0A   
+labels = labelNames.map(makeLabel);%0A  return %7B%0A
    
+ 
 id
-: 1
 ,%0A    
- 
- 
 labels
-: %5B%0A        %7B%0A          name: 'bug',%0A        %7D,%0A        %7B%0A          name: 'feature',%0A        %7D,%0A      %5D,%0A    %7D
+,%0A  %7D;%0A%7D%0A%0Adescribe('getLabels', () =%3E %7B%0A  it('returns the labels of an issue', () =%3E %7B%0A    const issue = makeIssue(%5B'bug', 'feature'%5D)
 ;%0A  
@@ -596,312 +596,88 @@
     
-%7B%0A        id: 1,%0A        labels: %5B%0A          %7B%0A            name: 'feature',%0A          %7D,%0A        %5D,%0A      %7D,%0A      %7B%0A        id: 2,%0A        labels: %5B%0A          %7B%0A            name: 'feature',%0A          %7D,%0A          %7B%0A            name: 'bug',%0A          %7D,%0A        %5D,%0A      %7D,%0A      %7B%0A        id: 3,%0A      %7D
+makeIssue(%5B'feature'%5D),%0A      makeIssue(%5B'feature', 'bug'%5D),%0A      makeIssue(%5B%5D)
 ,%0A  
@@ -882,101 +882,30 @@
 e = 
-%7B%0A      id: 1,%0A      labels: %5B%0A        %7B%0A          name: 'feature',%0A        %7D,%0A      %5D,%0A    %7D
+makeIssue(%5B'feature'%5D)
 ;%0A  
@@ -1197,546 +1197,206 @@
     
-%7B%0A        id: 1,%0A        labels: %5B%0A          %7B%0A            name: 'feature',%0A          %7D,%0A        %5D,%0A      %7D,%0A      %7B%0A        id: 2,%0A        labels: %5B%0A          %7B%0A            name: 'feature',%0A          %7D,%0A          %7B%0A            name: 'bug',%0A          %7D,%0A        %5D,%0A      %7D,%0A      %7B%0A        id: 3,%0A      %7D,%0A    %5D;%0A    expect(filterIssuesWithLabels(issues, %5B'bug'%5D)).toEqual(%5B%0A      %7B%0A        id: 2,%0A        labels: %5B%0A          %7B%0A            name: 'feature',%0A          %7D,%0A          %7B%0A            name: 'bug',%0A          %7D,%0A        %5D,%0A      %7D
+makeIssue(%5B'feature'%5D, 1),%0A      makeIssue(%5B'feature', 'bug'%5D, 2),%0A      makeIssue(%5B%5D, 3),%0A    %5D;%0A    expect(filterIssuesWithLabels(issues, %5B'bug'%5D)).toEqual(%5B%0A      makeIssue(%5B'feature', 'bug'%5D, 2)
 ,%0A  

Refactor labels tests