Enhance service

This commit is contained in:
Manuel Bouza
2019-02-07 18:26:15 +01:00
parent 7ad7cab5c0
commit cef97a5829
15 changed files with 210 additions and 112 deletions

65
test/utils/index.test.js Normal file
View File

@@ -0,0 +1,65 @@
import { projects } from "../data"
import {
findLastProject,
findLastTask,
groupedProjectOptions
} from "../../src/js/utils"
import { map } from "lodash/fp"
describe("utils", () => {
describe("findLastProject", () => {
it("finds an existing project", () => {
const options = groupedProjectOptions(projects)
const project = findLastProject(944837106)(options)
expect(project.value).toEqual(944837106)
expect(project.label).toEqual("Support")
expect(project.customerName).toEqual("MOCO APP")
expect(project.tasks).toHaveLength(4)
})
it("returns undefined if project is not found", () => {
const options = groupedProjectOptions(projects)
const project = findLastProject(123)(options)
expect(project).toBe(undefined)
})
it("returns undefined for undefined id", () => {
const options = groupedProjectOptions(projects)
const project = findLastProject(undefined)(options)
expect(project).toBe(undefined)
})
})
describe("findLastTask", () => {
it("find an existing task", () => {
const options = groupedProjectOptions(projects)
const project = findLastProject(944837106)(options)
const task = findLastTask(2506050)(project)
expect(task.value).toEqual(2506050)
expect(task.label).toEqual("Calls")
})
it("returns undefined if task is not found", () => {
const options = groupedProjectOptions(projects)
const project = findLastProject(944837106)(options)
const task = findLastTask(123)(project)
expect(task).toBe(undefined)
})
it("returns undefined for undefined project", () => {
const task = findLastTask(2506050)(undefined)
expect(task).toBe(undefined)
})
})
describe("groupedProjectOptions", () => {
it("transforms projects into grouped options by company", () => {
const result = groupedProjectOptions(projects)
expect(map("label", result)).toEqual([
"Simplificator",
"MOCO APP",
"sharoo"
])
})
})
})

View File

@@ -0,0 +1,64 @@
import { remoteServices } from '../data'
import { parseServices, createMatcher, createEnhancer } from '../../src/js/utils/urlMatcher'
import Route from "route-parser"
describe('utils', () => {
describe("urlMatcher", () => {
describe("parseServices", () => {
it("parses the services", () => {
const services = parseServices(remoteServices)
let service = services[0]
expect(service.key).toEqual("github-pr")
expect(service.name).toEqual("github")
expect(service.route).toBeInstanceOf(Route)
service = services[1]
expect(service.key).toEqual("jira-cloud")
expect(service.name).toEqual("jira")
expect(service.route).toBeInstanceOf(Route)
})
})
describe("createMatcher", () => {
let services, matcher
beforeEach(() => {
services = parseServices(remoteServices)
matcher = createMatcher(services)
})
it('matches host and path', () => {
const service = matcher('https://github.com/hundertzehn/mocoapp/pull/123')
expect(service.key).toEqual('github-pr')
expect(service.name).toEqual('github')
})
it('matches query string', () => {
const service = matcher('https://cloud.jira.com/browse?project=mocoapp&issue=1234')
expect(service.key).toEqual('jira-cloud')
expect(service.name).toEqual('jira')
})
it('does not match different host', () => {
const service = matcher('https://trello.com/hundertzehn/mocoapp/pull/123')
expect(service).toBeFalsy()
})
})
describe("createEnhancer", () => {
it("enhances a services", () => {
const url = 'https://github.com/hundertzehn/mocoapp/pull/123'
const document = {
querySelector: jest.fn().mockReturnValue({ textContent: '[4321] Foo' })
}
const enhancedService = createEnhancer(document)(remoteServices)('github-pr', url)
expect(enhancedService.id).toEqual( 'hundertzehn-mocoapp-github-pr-123')
expect(enhancedService.description).toEqual('This is always the same text')
expect(enhancedService.projectId).toEqual('4321')
expect(enhancedService.taskId).toBe(undefined)
})
})
})
})