|
| 1 | +"use strict" |
| 2 | + |
| 3 | +const request = require("superagent") |
| 4 | +const saMock = require("superagent-mocker")(request) |
| 5 | + |
| 6 | +const helper = require("./../helper") |
| 7 | +const route4me = require("./../../dist") |
| 8 | + |
| 9 | +const testApiKey = "11111111111111111111111111111111" |
| 10 | + |
| 11 | +describe(helper.toSuiteName(__filename), () => { |
| 12 | + describe("SDK methods", () => { |
| 13 | + const route4meClient = new route4me.Route4Me(testApiKey) |
| 14 | + const resource = route4meClient.AddressBarcodes |
| 15 | + let req |
| 16 | + |
| 17 | + beforeEach(() => { |
| 18 | + req = null |
| 19 | + saMock.get("*", (r) => { req = r; req.method = "GET"; return {} }) |
| 20 | + saMock.post("*", (r) => { req = r; req.method = "POST"; return {} }) |
| 21 | + }) |
| 22 | + |
| 23 | + afterEach(() => { |
| 24 | + saMock.clearRoutes() |
| 25 | + }) |
| 26 | + |
| 27 | + describe("get", () => { |
| 28 | + const routeId = "C50594BD37618FA8B28EE6A86FEFD9D1" |
| 29 | + const routeDestinationId = 2 |
| 30 | + const limit = 10 |
| 31 | + const cursor = "a" |
| 32 | + |
| 33 | + it("should call route4me", (done) => { |
| 34 | + |
| 35 | + resource.get(routeId, routeDestinationId, limit, cursor, (err, res) => { |
| 36 | + expect(err).is.null |
| 37 | + expect(res).is.not.null |
| 38 | + helper.expectRequest(req, |
| 39 | + "GET", "https://wh.route4me.com/modules/api/v5.0/address-barcodes", |
| 40 | + { |
| 41 | + "route_id": "C50594BD37618FA8B28EE6A86FEFD9D1", |
| 42 | + "route_destination_id": "2", |
| 43 | + "limit": "10", |
| 44 | + "cursor": "a" |
| 45 | + }, |
| 46 | + null |
| 47 | + ) |
| 48 | + done() |
| 49 | + }) |
| 50 | + }) |
| 51 | + |
| 52 | + it("should call route4me without cursor", (done) => { |
| 53 | + |
| 54 | + resource.get(routeId, routeDestinationId, limit, (err, res) => { |
| 55 | + expect(err).is.null |
| 56 | + expect(res).is.not.null |
| 57 | + helper.expectRequest(req, |
| 58 | + "GET", "https://wh.route4me.com/modules/api/v5.0/address-barcodes", |
| 59 | + { |
| 60 | + "route_id": "C50594BD37618FA8B28EE6A86FEFD9D1", |
| 61 | + "route_destination_id": "2", |
| 62 | + "limit": "10" |
| 63 | + }, |
| 64 | + null |
| 65 | + ) |
| 66 | + done() |
| 67 | + }) |
| 68 | + }) |
| 69 | + }) |
| 70 | + |
| 71 | + describe("save", () => { |
| 72 | + const data = { |
| 73 | + barcodes: [{ |
| 74 | + barcode: "some barcode", |
| 75 | + lat: 1, |
| 76 | + lng: 2, |
| 77 | + timestamp_date: 3, |
| 78 | + timestamp_utc: 4, |
| 79 | + scanned_at: "2022-03-17 00:01:02", |
| 80 | + scan_type: "QR-code" |
| 81 | + }, { |
| 82 | + barcode: "ye some barcode", |
| 83 | + lat: 5, |
| 84 | + lng: 6, |
| 85 | + timestamp_date: 7, |
| 86 | + timestamp_utc: 8, |
| 87 | + scanned_at: "2022-03-18 01:02:03", |
| 88 | + scan_type: "QR-code" |
| 89 | + }], |
| 90 | + route_destination_id: 1, |
| 91 | + route_id: "C50594BD37618FA8B28EE6A86FEFD9D1" |
| 92 | + }; |
| 93 | + |
| 94 | + it("should call route4me", (done) => { |
| 95 | + resource.save(data, (err, res) => { |
| 96 | + expect(err).is.null |
| 97 | + expect(res).is.not.null |
| 98 | + helper.expectRequest(req, |
| 99 | + "POST", "https://wh.route4me.com/modules/api/v5.0/address-barcodes", {}, |
| 100 | + data |
| 101 | + ) |
| 102 | + done() |
| 103 | + }) |
| 104 | + }) |
| 105 | + }) |
| 106 | + }) |
| 107 | +}) |
0 commit comments