/* eslint-env node, jest */

jest.mock('axios');

const channelNotifier = require('./index.js');
const Slack = require('../lib/slackMock.js');

let slack = null;

beforeEach(() => {
	slack = new Slack();
	process.env.CHANNEL_RANDOM = slack.fakeChannel;
	channelNotifier(slack);
});

it('responds to channel creation', () => new Promise((resolve) => {
	slack.on('chat.postMessage', ({channel, text, username, icon_emoji: icon}) => {
		expect(channel).toBe(slack.fakeChannel);
		expect(username).toBe('channel-notifier');
		expect(text).toContain('fun');
		expect(text).toContain('作成');
		expect(icon).toBe(':new:');
		resolve();
	});

	// https://api.slack.com/events/channel_created
	slack.rtmClient.emit('channel_created', {
		channel: {
			id: 'C024BE91L',
			name: 'fun',
			created: 1360782804,
			creator: 'U024BE7LH',
		},
	});
}));

@@ -276,16 +276,54 @@
 );%0A%7D);%0A%0A
+describe('channel-notifier', () =%3E %7B%0A%09
 it('resp
@@ -378,24 +378,25 @@
 solve) =%3E %7B%0A
+%09
 %09slack.on('c
@@ -442,34 +442,16 @@
 name
-, icon_emoji: icon
 %7D) =%3E %7B%0A
 %09%09ex
@@ -446,16 +446,17 @@
 %7D) =%3E %7B%0A
+%09
 %09%09expect
@@ -488,24 +488,25 @@
 Channel);%0A%09%09
+%09
 expect(usern
@@ -534,24 +534,25 @@
 tifier');%0A%09%09
+%09
 expect(text)
@@ -567,15 +567,22 @@
 in('
-fun
+U024BE7LH
 ');%0A
+%09
 %09%09ex
@@ -607,44 +607,55 @@
 in('
-%E4%BD%9C%E6%88%90
+C024BE91L
 ');%0A%09%09
+%09
 expect(
-icon).toBe(':new:
+text).toContain('%E4%BD%9C%E6%88%90
 ');%0A
+%09
 %09%09re
@@ -667,14 +667,16 @@
 ();%0A
+%09
 %09%7D);%0A%0A
+%09
 %09// 
@@ -720,16 +720,17 @@
 created%0A
+%09
 %09slack.r
@@ -764,16 +764,17 @@
 ted', %7B%0A
+%09
 %09%09channe
@@ -781,16 +781,17 @@
 l: %7B%0A%09%09%09
+%09
 id: 'C02
@@ -799,16 +799,17 @@
 BE91L',%0A
+%09
 %09%09%09name:
@@ -815,24 +815,25 @@
 : 'fun',%0A%09%09%09
+%09
 created: 136
@@ -841,16 +841,17 @@
 782804,%0A
+%09
 %09%09%09creat
@@ -871,19 +871,573 @@
 H',%0A
+%09
 %09%09%7D,%0A
+%09
 %09%7D);%0A
+%09
 %7D));%0A
+%0A%09it('responds to channel unarchive', () =%3E new Promise((resolve) =%3E %7B%0A%09%09slack.on('chat.postMessage', (%7Bchannel, text, username%7D) =%3E %7B%0A%09%09%09expect(channel).toBe(slack.fakeChannel);%0A%09%09%09expect(username).toBe('channel-notifier');%0A%09%09%09expect(text).toContain('U024BE7LH');%0A%09%09%09expect(text).toContain('C024BE91L');%0A%09%09%09expect(text).toContain('%E5%BE%A9%E5%85%83');%0A%09%09%09resolve();%0A%09%09%7D);%0A%0A%09%09// https://api.slack.com/events/channel_unarchiveu%0A%09%09slack.rtmClient.emit('channel_unarchive', %7B%0A%09%09%09type: 'channel_unarchive',%0A%09%09%09channel: 'C024BE91L',%0A%09%09%09user: 'U024BE7LH',%0A%09%09%7D);%0A%09%7D));%0A%7D);%0A

Fix test and resolve #208