Skip to content

Commit

Permalink
Merge pull request #87 from mozilla-services/deprecation-header-integ…
Browse files Browse the repository at this point in the history
…ration-test

Fixes #85 - Added integration test for deprecation headers.
  • Loading branch information
n1k0 committed Jul 21, 2015
2 parents b8139a7 + d53d833 commit a0e3ec5
Showing 1 changed file with 51 additions and 2 deletions.
53 changes: 51 additions & 2 deletions test/integration_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { v4 as uuid4 } from "uuid";
import btoa from "btoa";
import chai, { expect } from "chai";
import chaiAsPromised from "chai-as-promised";
import sinon from "sinon";
import Kinto from "../src";
import { cleanRecord } from "../src/api";

Expand All @@ -18,7 +19,7 @@ const PSERVE_EXECUTABLE = process.env.KINTO_PSERVE_EXECUTABLE || "pserve";
const KINTO_CONFIG = __dirname + "/kinto.ini";

describe("Integration tests", () => {
var server, tasks;
var sandbox, server, tasks;
const MAX_ATTEMPTS = 50;

function startServer(env={}) {
Expand All @@ -39,7 +40,7 @@ describe("Integration tests", () => {
function flushServer(attempt=1) {
return fetch(`${TEST_KINTO_SERVER}/__flush__`, {method: "POST"})
.then(res => {
if (res.status !== 202)
if ([202, 410].indexOf(res.status) === -1)
throw new Error("Unable to flush test server.");
})
.catch(err => {
Expand All @@ -57,6 +58,8 @@ describe("Integration tests", () => {
beforeEach(function() {
this.timeout(12500);

sandbox = sinon.sandbox.create();

tasks = new Kinto({
remote: TEST_KINTO_SERVER,
headers: {Authorization: "Basic " + btoa("user:pass")}
Expand All @@ -65,6 +68,8 @@ describe("Integration tests", () => {
return tasks.clear().then(_ => flushServer());
});

afterEach(() => sandbox.restore());

function testSync(data) {
return Promise.all([].concat(
// Create local unsynced records
Expand Down Expand Up @@ -320,4 +325,48 @@ describe("Integration tests", () => {
.should.be.rejectedWith(Error, /Server is backed off; retry in 10s/);
});
});

describe("Deprecated protocol version", () => {
describe("Soft EOL", () => {
before(() => {
const tomorrow = new Date(new Date().getTime() + 86400000).toJSON().slice(0, 10);
startServer({
CLIQUET_EOS: tomorrow,
CLIQUET_EOS_URL: "http://www.perdu.com",
CLIQUET_EOS_MESSAGE: "Boom",
});
});

after(() => stopServer());

beforeEach(() => sandbox.stub(console, "warn"));

it("should warn when the server sends a deprecation Alert header", () => {
return tasks.sync()
.then(_ => {
sinon.assert.calledWithExactly(console.warn, "Boom", "http://www.perdu.com");
});
});
});

describe("Hard EOL", () => {
before(() => {
const lastWeek = new Date(new Date().getTime() - (7 * 86400000)).toJSON().slice(0, 10);
startServer({
CLIQUET_EOS: lastWeek,
CLIQUET_EOS_URL: "http://www.perdu.com",
CLIQUET_EOS_MESSAGE: "Boom",
});
});

after(() => stopServer());

beforeEach(() => sandbox.stub(console, "warn"));

it("should reject with a 410 Gone when hard EOL is received", () => {
return tasks.sync()
.should.be.rejectedWith(Error, /HTTP 410; Service deprecated/);
});
});
});
});

0 comments on commit a0e3ec5

Please sign in to comment.