summaryrefslogtreecommitdiffstatshomepage
path: root/test/ext/method-override.js
blob: b0a21ea1df9db1f98ccb86fb9612cce8d70a8c6f (plain) (blame)
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
describe("method-override extension", function(){
    beforeEach(function() {
        this.server = makeServer();
        clearWorkArea();
    });
    afterEach(function()  {
        this.server.restore();
        clearWorkArea();
    });

    it('issues a DELETE request with proper headers', function()
    {
        this.server.respondWith("DELETE", "/test", function(xhr){
            xhr.requestHeaders['X-HTTP-Method-Override'].should.equal('DELETE');
            xhr.method.should.equal("POST")
            xhr.respond(200, {}, "Deleted!");
        });

        var btn = make('<button hx-ext="method-override" hx-delete="/test">Click Me!</button>')
        btn.click();
        this.server.respond();
        btn.innerHTML.should.equal("Deleted!");
    });

    it('issues a PATCH request with proper headers', function()
    {
        this.server.respondWith("PATCH", "/test", function(xhr){
            xhr.requestHeaders['X-HTTP-Method-Override'].should.equal('PATCH');
            xhr.method.should.equal("POST")
            xhr.respond(200, {}, "Patched!");
        });

        var btn = make('<button hx-ext="method-override" hx-patch="/test">Click Me!</button>')
        btn.click();
        this.server.respond();
        btn.innerHTML.should.equal("Patched!");
    });

    it('issues a PUT request with proper headers', function()
    {
        this.server.respondWith("PUT", "/test", function(xhr){
            xhr.requestHeaders['X-HTTP-Method-Override'].should.equal('PUT');
            xhr.method.should.equal("POST")
            xhr.respond(200, {}, "Putted!");
        });

        var btn = make('<button hx-ext="method-override" hx-put="/test">Click Me!</button>')
        btn.click();
        this.server.respond();
        btn.innerHTML.should.equal("Putted!");
    });

})