Skip to content

Commit

Permalink
backend: add test to handle payments with opencollective
Browse files Browse the repository at this point in the history
  • Loading branch information
elhmn committed May 28, 2023
1 parent 6bd553d commit 1426d57
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
46 changes: 46 additions & 0 deletions backend/e2etests/pay.test.after.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { expect } from "chai";
import request from "supertest";
import dotenv from "dotenv";

dotenv.config();
const apiHost = process.env.API_HOST;
const endpoint = "pay";

describe(`${endpoint}`, function () {
describe("POST", function () {
it("fails to make a payment with invalid email address", async function () {
return request(apiHost)
.post(`${endpoint}`)
.set("Accept", "application/json")
.send({
email: "wrong email",
tier: "new jobsika tier",
job_offer_id: "1",
})
.expect(400)
.expect("Content-Type", "application/json; charset=utf-8")
.then((res) => {
expect(JSON.stringify(res.body)).contain("email field is invalid");
});
});

it("proceed with a payment", async function () {
return request(apiHost)
.post(`${endpoint}`)
.set("Accept", "application/json")
.send({
email: "[email protected]",
tier: "new jobsika tier",
job_offer_id: "1",
})
.expect(200)
.expect("Content-Type", "application/json; charset=utf-8")
.then((res) => {
expect(JSON.stringify(res.body)).contain(
"opencollective.com"
);
});
});

});
});
9 changes: 9 additions & 0 deletions backend/internal/handlers/pay_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"net/http"
"os"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -40,6 +41,14 @@ func PostPay(c *gin.Context) {
return
}

//We can't proceed with a payment on test mode as this will create unecessary
//payment on opencollective
if os.Getenv("TEST") == "true" {
//Send the link to the newly created opencollective tier to back to the client
c.JSON(http.StatusOK, gin.H{"tier_url": "https://opencollective.com/osscameroon/something-something"})
return
}

//Create a new opencollective tier
//The deletion should happen on the webhook or a day after created
paymentClient, err := server.GetDefaultPaymentClient()
Expand Down

0 comments on commit 1426d57

Please sign in to comment.