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 6a36d00
Show file tree
Hide file tree
Showing 2 changed files with 56 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"
);
});
});

});
});
10 changes: 10 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 @@ -75,6 +76,15 @@ func PostPay(c *gin.Context) {
}

url := fmt.Sprintf("%s%s-%d", payment.OPEN_COLLECTIVE_CONTRIBUTE, response.CreateTier.Slug, response.CreateTier.LegacyID)

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

err = db.CreatePaymentRecord(&v1beta.PaymentRecord{
TierId: response.CreateTier.ID,
JobOfferID: jobOfferID,
Expand Down

0 comments on commit 6a36d00

Please sign in to comment.