aboutsummaryrefslogtreecommitdiffstats
path: root/web/src/js/__tests__/flow/utilsSpec.js
blob: 24e6565151dfb0c2d2e54bcd44018540c6962570 (plain)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import * as utils from '../../flow/utils'

describe('MessageUtils', () => {
    it('should be possible to get first header', () => {
        let msg = { headers: [["foo", "bar"]]}
        expect(utils.MessageUtils.get_first_header(msg, "foo")).toEqual("bar")
        expect(utils.MessageUtils.get_first_header(msg, "123")).toEqual(undefined)
    })

    it('should be possible to get Content-Type', () => {
        let type = "text/html",
            msg = { headers: [["Content-Type", type]]}
        expect(utils.MessageUtils.getContentType(msg)).toEqual(type)
    })

    it('should be possible to match header', () => {
        let h1 = ["foo", "bar"],
            msg = {headers : [h1]}
        expect(utils.MessageUtils.match_header(msg, /foo/i)).toEqual(h1)
        expect(utils.MessageUtils.match_header(msg, /123/i)).toBeFalsy()
    })

    it('should be possible to get content URL', () => {
        // request
        let msg = "foo", view = "bar",
            flow = { request: msg, id: 1}
        expect(utils.MessageUtils.getContentURL(flow, msg, view)).toEqual(
            "/flows/1/request/content/bar.json"
        )
        expect(utils.MessageUtils.getContentURL(flow, msg, '')).toEqual(
            "/flows/1/request/_content"
        )
        // response
        flow = {response: msg, id: 2}
        expect(utils.MessageUtils.getContentURL(flow, msg, view)).toEqual(
            "/flows/2/response/content/bar.json"
        )
    })
})

describe('RequestUtils', () => {
    it('should be possible prettify url', () => {
        let request = {port: 4444, scheme: "http", pretty_host: "foo", path: "/bar"}
        expect(utils.RequestUtils.pretty_url(request)).toEqual(
            "http://foo:4444/bar"
        )
    })
})

describe('parseUrl', () => {
    it('should be possible to parse url', () => {
        let url = "http://foo:4444/bar"
        expect(utils.parseUrl(url)).toEqual({
            port: 4444,
            scheme: 'http',
            host: 'foo',
            path: '/bar'
        })

        expect(utils.parseUrl("foo:foo")).toBeFalsy()
    })
})

describe('isValidHttpVersion', () => {
    it('should be possible to validate http version', () => {
        expect(utils.isValidHttpVersion("HTTP/1.1")).toBeTruthy()
        expect(utils.isValidHttpVersion("HTTP//1")).toBeFalsy()
    })
})