dongnelibrary 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "engines": {
4
4
  "node": ">=16.0.0"
5
5
  },
6
- "version": "0.2.1",
6
+ "version": "0.2.2",
7
7
  "description": "책을 빌릴 수 있는지 확인한다.",
8
8
  "main": "src/dongnelibrary.js",
9
9
  "bin": {
package/src/library/gg.js CHANGED
@@ -70,7 +70,7 @@ function search(opt, getBook) {
70
70
  } else {
71
71
  const dom = new JSDOM(body);
72
72
  const $counter = dom.window.document.querySelector('#search_result > div.research-box > div.search-info > b')
73
- const count = Number($counter.innerHTML)
73
+ const count = $counter ? Number($counter.innerHTML) : 0;
74
74
  // const $row = dom.window.document.querySelectorAll('.row .book-title')
75
75
  const $ = jquery(dom.window)
76
76
  const booklist = []
@@ -78,12 +78,14 @@ function search(opt, getBook) {
78
78
  const title = $(a).find('.book-title > span').text().trim()
79
79
  const rented = $(a).find('.state.typeC').text().trim()
80
80
  const libraryName = $(a).find("span:contains('도서관')").next().text().split('|')[0].trim()
81
- booklist.push({
82
- libraryName,
83
- title,
84
- maxoffset: count,
85
- exist: rented === '대출가능'
86
- });
81
+ if (title) {
82
+ booklist.push({
83
+ libraryName,
84
+ title,
85
+ maxoffset: count,
86
+ exist: rented === '대출가능'
87
+ });
88
+ }
87
89
  })
88
90
  getBook(null, {
89
91
  startPage: opt.startPage,
@@ -68,13 +68,16 @@ function search(opt, getBook) {
68
68
  $('.resultList > li').each((_, a) => {
69
69
  const title = $(a).find('.tit a').text().trim()
70
70
  const rented = $(a).find('.bookStateBar .txt b').text().trim()
71
- const libraryName = $(a).find('.site > span:first-child').text().split(']')[1].trim()
72
- booklist.push({
73
- libraryName,
74
- title,
75
- maxoffset: count,
76
- exist: rented.includes('대출가능')
77
- });
71
+ const b = $(a).find('.site > span:first-child').text().split(']')
72
+ const libraryName = b && b[1] ? b[1].trim() : ''
73
+ if (title) {
74
+ booklist.push({
75
+ libraryName,
76
+ title,
77
+ maxoffset: count,
78
+ exist: rented.includes('대출가능')
79
+ });
80
+ }
78
81
  })
79
82
  getBook(null, {
80
83
  startPage: opt.startPage,
package/test/gg.spec.js CHANGED
@@ -4,11 +4,55 @@ const util = require('../src/util.js');
4
4
 
5
5
  describe('경기도 도서관 (제한시간 20초)', function () {
6
6
  this.timeout(20000);
7
+
7
8
  it('Show library list', function (done) {
8
9
  assert.ok(lib.getLibraryNames().length > 1);
9
10
  done();
10
11
  });
11
12
 
13
+ it('Use empty book title', function (done) {
14
+ lib.search({
15
+ title: '',
16
+ libraryName: '경기평택교육도서관',
17
+ startPage: 1
18
+ }, function (err) {
19
+ if(err) {
20
+ assert.ok(err.msg === 'Need a book name');
21
+ } else {
22
+ assert.fail('Need a error msg')
23
+ }
24
+ done();
25
+ });
26
+ });
27
+
28
+ it('Use invalid book title', function (done) {
29
+ lib.search({
30
+ title: 'zyxwvutsrqponmlkjihgfedcbaabcdefghijklmnopqrstuvwxyz',
31
+ libraryName: '경기평택교육도서관',
32
+ startPage: 1
33
+ }, function (err, book) {
34
+ if(err) {
35
+ assert.fail('must have an empty booklist');
36
+ }
37
+ assert.equal(book.booklist.length, 0)
38
+ done();
39
+ });
40
+ });
41
+
42
+ it('Use empty library name', function (done) {
43
+ lib.search({
44
+ title: '자바스크립트',
45
+ libraryName: '',
46
+ startPage: 1
47
+ }, function (err, book) {
48
+ if(err) {
49
+ assert.ok(err.msg === 'Need a library name');
50
+ }
51
+ assert.equal(book, undefined)
52
+ done();
53
+ });
54
+ });
55
+
12
56
  it('Show book list of one library', function (done) {
13
57
  lib.search({
14
58
  title: 'javascript',
@@ -28,4 +72,5 @@ describe('경기도 도서관 (제한시간 20초)', function () {
28
72
  done();
29
73
  });
30
74
  });
75
+
31
76
  });
package/test/osan.spec.js CHANGED
@@ -4,11 +4,41 @@ const util = require('../src/util.js');
4
4
 
5
5
  describe('오산시 도서관 (제한시간 20초)', function () {
6
6
  this.timeout(20000);
7
+
7
8
  it('Show library list', function (done) {
8
9
  assert.ok(lib.getLibraryNames().length > 1);
9
10
  done();
10
11
  });
11
12
 
13
+ it('Use empty book title', function (done) {
14
+ lib.search({
15
+ title: '',
16
+ libraryName: '양산도서관',
17
+ startPage: 1
18
+ }, function (err) {
19
+ if(err) {
20
+ assert.ok(err.msg === 'Need a book name');
21
+ } else {
22
+ assert.fail('Need a error msg')
23
+ }
24
+ done();
25
+ });
26
+ });
27
+
28
+ it('Use invalid book title', function (done) {
29
+ lib.search({
30
+ title: 'zyxwvutsrqponmlkjihgfedcbaabcdefghijklmnopqrstuvwxyz',
31
+ libraryName: '양산도서관',
32
+ startPage: 1
33
+ }, function (err, book) {
34
+ if(err) {
35
+ assert.fail('must have an empty booklist');
36
+ }
37
+ assert.equal(book.booklist.length, 0)
38
+ done();
39
+ });
40
+ });
41
+
12
42
  it('Show book list of one library', function (done) {
13
43
  lib.search({
14
44
  title: 'javascript',
@@ -29,7 +59,6 @@ describe('오산시 도서관 (제한시간 20초)', function () {
29
59
  });
30
60
  });
31
61
 
32
-
33
62
  it('Show book list of all libraries', function (done) {
34
63
  lib.search({
35
64
  title: 'javascript',