Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Testable Examples #53

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions test/examples.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
const zulip = require('../lib/index');
const chai = require('chai');
const fs = require('fs');
chai.use(require('chai-as-promised'));

chai.should();
const fixtures = JSON.parse(fs.readFileSync('./test/fixtures.json', 'utf-8'));
const examples = [];
// Just the tokens for my local test server. Temporary.
const config = {
username: 'cookie-bot@localhost',
apiKey: 'dLfydLvW3tJvSjwXZscOWKDyfl2vPfLI',
realm: 'http://localhost:9991/api',
};

examples.push({
name: 'stream-message',
code(client) {
// {code_example|start}
return client.messages.send({
to: 'Denmark',
type: 'stream',
subject: 'Castle',
content: 'Something is rotten in the state of Denmark.',
});
// {code_example|end}
},
});

examples.push({
name: 'private-message',
code(client) {
// {code_example|start}
return client.messages.send({
type: 'private',
to: '[email protected]',
content: 'I come not, friends, to steal away your hearts.',
});
// {code_example|end}
},
});

describe('Examples', () => {
it('should begin testing', (done) => {
// Without something like this, it doesn't detect other tests.
// Weird, but can work around by simply placing an empty test.
done();
});
zulip(config).then((client) => {
examples.forEach((elem) => {
it(`should pass example: ${elem.name}`, (done) => {
elem.code(client).then((result) => {
result.should.deep.equal(fixtures[elem.name]);
done();
}).catch(done);
});
});
});
});

// // Strings for adding to the example in the markdown.
// const preExample = `
// const zulip = require('zulip-js');
// // Download zuliprc-dev from your dev server
// const config = {
// zuliprc: 'zuliprc-dev',
// };
// zulip(config).then((client) => {
// `;

// const postExample = `
// .then((result) => {
// console.log(result);
// })
// .catch((error) => {
// console.error(error);
// });
// `;
Loading