|
1 | 1 | import { expect } from 'chai'; |
2 | | -import * as semver from 'semver'; |
| 2 | +import { satisfies } from 'semver'; |
3 | 3 |
|
| 4 | +import type { MongoClient } from '../../../src'; |
4 | 5 | import { assert as test, setupDatabase } from '../shared'; |
5 | 6 |
|
6 | | -describe.only('Unicode', function () { |
| 7 | +describe('Unicode', function () { |
| 8 | + let client: MongoClient; |
| 9 | + |
7 | 10 | before(function () { |
8 | 11 | return setupDatabase(this.configuration); |
9 | 12 | }); |
10 | 13 |
|
11 | | - it('shouldCorrectlyInsertUnicodeContainingDocument', { |
12 | | - metadata: { |
13 | | - requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } |
14 | | - }, |
| 14 | + beforeEach(async function () { |
| 15 | + client = this.configuration.newClient(); |
| 16 | + }); |
15 | 17 |
|
16 | | - test: function (done) { |
17 | | - if (semver.satisfies(process.versions.node, '22.7.0')) { |
18 | | - this.skipReason = 'Node.js 22.7.0 has a UTF-8 encoding bug'; |
19 | | - this.skip(); |
20 | | - } |
| 18 | + afterEach(async function () { |
| 19 | + await client?.close(); |
| 20 | + }); |
21 | 21 |
|
22 | | - const configuration = this.configuration; |
23 | | - const client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 }); |
24 | | - client.connect(function (err, client) { |
25 | | - const db = client.db(configuration.db); |
26 | | - const doc = { |
27 | | - statuses_count: 1687, |
28 | | - created_at: 'Mon Oct 22 14:55:08 +0000 2007', |
29 | | - description: 'NodeJS hacker, Cofounder of Debuggable, CakePHP core alumnus', |
30 | | - favourites_count: 6, |
31 | | - profile_sidebar_fill_color: 'EADEAA', |
32 | | - screen_name: 'felixge', |
33 | | - status: { |
34 | | - created_at: 'Fri Mar 12 08:59:44 +0000 2010', |
35 | | - in_reply_to_screen_name: null, |
36 | | - truncated: false, |
37 | | - in_reply_to_user_id: null, |
38 | | - source: '<a href="http://www.atebits.com/" rel="nofollow">Tweetie</a>', |
39 | | - favorited: false, |
40 | | - in_reply_to_status_id: null, |
41 | | - id: 10364119169, |
42 | | - text: '#berlin #snow = #fail : (' |
43 | | - }, |
44 | | - contributors_enabled: false, |
45 | | - following: null, |
46 | | - geo_enabled: false, |
47 | | - time_zone: 'Eastern Time (US & Canada)', |
48 | | - profile_sidebar_border_color: 'D9B17E', |
49 | | - url: 'http://debuggable.com', |
50 | | - verified: false, |
51 | | - location: 'Berlin', |
52 | | - profile_text_color: '333333', |
53 | | - notifications: null, |
54 | | - profile_background_image_url: |
55 | | - 'http://s.twimg.com/a/1268354287/images/themes/theme8/bg.gif', |
56 | | - protected: false, |
57 | | - profile_link_color: '9D582E', |
58 | | - followers_count: 840, |
59 | | - name: 'Felix Geisend\u00f6rfer', |
60 | | - profile_background_tile: false, |
61 | | - id: 9599342, |
62 | | - lang: 'en', |
63 | | - utc_offset: -18000, |
64 | | - friends_count: 450, |
65 | | - profile_background_color: '8B542B', |
66 | | - profile_image_url: |
67 | | - 'http://a3.twimg.com/profile_images/107142257/passbild-square_normal.jpg' |
68 | | - }; |
| 22 | + it('shouldCorrectlyInsertUnicodeContainingDocument', async function () { |
| 23 | + if (satisfies(process.versions.node, '22.7.0')) { |
| 24 | + this.skipReason = 'Node.js 22.7.0 has a UTF-8 encoding bug'; |
| 25 | + this.skip(); |
| 26 | + } |
69 | 27 |
|
70 | | - db.createCollection( |
71 | | - 'test_should_correctly_insert_unicode_containing_document', |
72 | | - function (err, collection) { |
73 | | - doc['_id'] = 'felixge'; |
| 28 | + const configuration = this.configuration; |
| 29 | + const db = client.db(configuration.db); |
| 30 | + const doc = { |
| 31 | + statuses_count: 1687, |
| 32 | + created_at: 'Mon Oct 22 14:55:08 +0000 2007', |
| 33 | + description: 'NodeJS hacker, Cofounder of Debuggable, CakePHP core alumnus', |
| 34 | + favourites_count: 6, |
| 35 | + profile_sidebar_fill_color: 'EADEAA', |
| 36 | + screen_name: 'felixge', |
| 37 | + status: { |
| 38 | + created_at: 'Fri Mar 12 08:59:44 +0000 2010', |
| 39 | + in_reply_to_screen_name: null, |
| 40 | + truncated: false, |
| 41 | + in_reply_to_user_id: null, |
| 42 | + source: '<a href="http://www.atebits.com/" rel="nofollow">Tweetie</a>', |
| 43 | + favorited: false, |
| 44 | + in_reply_to_status_id: null, |
| 45 | + id: 10364119169, |
| 46 | + text: '#berlin #snow = #fail : (' |
| 47 | + }, |
| 48 | + contributors_enabled: false, |
| 49 | + following: null, |
| 50 | + geo_enabled: false, |
| 51 | + time_zone: 'Eastern Time (US & Canada)', |
| 52 | + profile_sidebar_border_color: 'D9B17E', |
| 53 | + url: 'http://debuggable.com', |
| 54 | + verified: false, |
| 55 | + location: 'Berlin', |
| 56 | + profile_text_color: '333333', |
| 57 | + notifications: null, |
| 58 | + profile_background_image_url: 'http://s.twimg.com/a/1268354287/images/themes/theme8/bg.gif', |
| 59 | + protected: false, |
| 60 | + profile_link_color: '9D582E', |
| 61 | + followers_count: 840, |
| 62 | + name: 'Felix Geisend\u00f6rfer', |
| 63 | + profile_background_tile: false, |
| 64 | + id: 9599342, |
| 65 | + lang: 'en', |
| 66 | + utc_offset: -18000, |
| 67 | + friends_count: 450, |
| 68 | + profile_background_color: '8B542B', |
| 69 | + profile_image_url: 'http://a3.twimg.com/profile_images/107142257/passbild-square_normal.jpg' |
| 70 | + }; |
74 | 71 |
|
75 | | - collection.insertOne(doc, { writeConcern: { w: 1 } }, function (err) { |
76 | | - expect(err).to.not.exist; |
77 | | - collection.findOne(function (err, doc) { |
78 | | - test.equal('felixge', doc._id); |
79 | | - client.close(done); |
80 | | - }); |
81 | | - }); |
82 | | - } |
83 | | - ); |
84 | | - }); |
85 | | - } |
86 | | - }); |
| 72 | + const collection = await db.createCollection( |
| 73 | + 'test_should_correctly_insert_unicode_containing_document' |
| 74 | + ); |
| 75 | + doc['_id'] = 'felixge'; |
87 | 76 |
|
88 | | - it('should Correctly Insert Unicode Characters', function (done) { |
89 | | - const client = this.configuration.newClient(this.configuration.writeConcernMax(), { |
90 | | - maxPoolSize: 1 |
91 | | - }); |
92 | | - client.connect((err, client) => { |
93 | | - expect(err).to.not.exist; |
94 | | - const db = client.db(this.configuration.db); |
95 | | - db.createCollection('unicode_test_collection', (err, collection) => { |
96 | | - expect(err).to.not.exist; |
97 | | - const test_strings = ['ouooueauiOUOOUEAUI', 'öüóőúéáűíÖÜÓŐÚÉÁŰÍ', '本荘由利地域に洪水警報']; |
98 | | - collection.insert({ id: 0, text: test_strings[0] }, { writeConcern: { w: 1 } }, err => { |
99 | | - expect(err).to.not.exist; |
100 | | - collection.insert({ id: 1, text: test_strings[1] }, { writeConcern: { w: 1 } }, err => { |
101 | | - expect(err).to.not.exist; |
102 | | - collection.find().forEach( |
103 | | - doc => { |
104 | | - expect(doc).property('text').to.equal(test_strings[doc.id]); |
105 | | - }, |
106 | | - err => { |
107 | | - expect(err).to.not.exist; |
108 | | - client.close(done); |
109 | | - } |
110 | | - ); |
111 | | - }); |
112 | | - }); |
113 | | - }); |
114 | | - }); |
| 77 | + await collection.insertOne(doc, { writeConcern: { w: 1 } }); |
| 78 | + const document = await collection.findOne(); |
| 79 | + test.equal('felixge', document._id); |
115 | 80 | }); |
116 | 81 |
|
117 | | - it('shouldCreateObjectWithChineseObjectName', { |
118 | | - metadata: { |
119 | | - requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } |
120 | | - }, |
| 82 | + it('should Correctly Insert Unicode Characters', async function () { |
| 83 | + const db = client.db(this.configuration.db); |
| 84 | + const collection = await db.createCollection('unicode_test_collection'); |
| 85 | + const test_strings = ['ouooueauiOUOOUEAUI', 'öüóőúéáűíÖÜÓŐÚÉÁŰÍ', '本荘由利地域に洪水警報']; |
| 86 | + await collection.insertOne({ id: 0, text: test_strings[0] }, { writeConcern: { w: 1 } }); |
| 87 | + await collection.insertOne({ id: 1, text: test_strings[1] }, { writeConcern: { w: 1 } }); |
121 | 88 |
|
122 | | - test: function (done) { |
123 | | - const object = { 客家话: 'Hello' }; |
| 89 | + const documents = await collection.find().toArray(); |
| 90 | + expect(documents[0]).property('text').to.equal(test_strings[documents[0].id]); |
| 91 | + expect(documents[1]).property('text').to.equal(test_strings[documents[1].id]); |
| 92 | + }); |
124 | 93 |
|
125 | | - const configuration = this.configuration; |
126 | | - const client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 }); |
127 | | - client.connect(function (err, client) { |
128 | | - const db = client.db(configuration.db); |
129 | | - db.createCollection('create_object_with_chinese_object_name', function (err) { |
130 | | - expect(err).to.not.exist; |
131 | | - const collection = db.collection('create_object_with_chinese_object_name'); |
132 | | - collection.insert(object, { writeConcern: { w: 1 } }, function (err) { |
133 | | - expect(err).to.not.exist; |
134 | | - collection.findOne(function (err, item) { |
135 | | - test.equal(object['客家话'], item['客家话']); |
| 94 | + it('shouldCreateObjectWithChineseObjectName', async function () { |
| 95 | + const object = { 客家话: 'Hello' }; |
136 | 96 |
|
137 | | - collection.find().toArray(function (err, items) { |
138 | | - test.equal(object['客家话'], items[0]['客家话']); |
139 | | - client.close(done); |
140 | | - }); |
141 | | - }); |
142 | | - }); |
143 | | - }); |
144 | | - }); |
145 | | - } |
146 | | - }); |
| 97 | + const configuration = this.configuration; |
| 98 | + const db = client.db(configuration.db); |
| 99 | + await db.createCollection('create_object_with_chinese_object_name'); |
| 100 | + const collection = db.collection('create_object_with_chinese_object_name'); |
| 101 | + await collection.insertOne(object, { writeConcern: { w: 1 } }); |
| 102 | + const item = await collection.findOne(); |
| 103 | + test.equal(object['客家话'], item['客家话']); |
147 | 104 |
|
148 | | - it('shouldCorrectlyHandleUT8KeyNames', { |
149 | | - metadata: { |
150 | | - requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } |
151 | | - }, |
| 105 | + const items = await collection.find().toArray(); |
| 106 | + test.equal(object['客家话'], items[0]['客家话']); |
| 107 | + }); |
152 | 108 |
|
153 | | - test: function (done) { |
154 | | - const configuration = this.configuration; |
155 | | - const client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 }); |
156 | | - client.connect(function (err, client) { |
157 | | - const db = client.db(configuration.db); |
158 | | - db.createCollection('test_utf8_key_name', function (err, collection) { |
159 | | - collection.insert({ šđžčćŠĐŽČĆ: 1 }, { writeConcern: { w: 1 } }, function (err) { |
160 | | - expect(err).to.not.exist; |
161 | | - collection |
162 | | - .find({}) |
163 | | - .project({ šđžčćŠĐŽČĆ: 1 }) |
164 | | - .toArray(function (err, items) { |
165 | | - test.equal(1, items[0]['šđžčćŠĐŽČĆ']); |
166 | | - // Let's close the db |
167 | | - client.close(done); |
168 | | - }); |
169 | | - }); |
170 | | - }); |
171 | | - }); |
172 | | - } |
| 109 | + it('shouldCorrectlyHandleUT8KeyNames', async function () { |
| 110 | + const configuration = this.configuration; |
| 111 | + const db = client.db(configuration.db); |
| 112 | + const collection = await db.createCollection('test_utf8_key_name'); |
| 113 | + await collection.insertOne({ šđžčćŠĐŽČĆ: 1 }, { writeConcern: { w: 1 } }); |
| 114 | + const items = await collection.find({}).project({ šđžčćŠĐŽČĆ: 1 }).toArray(); |
| 115 | + test.equal(1, items[0]['šđžčćŠĐŽČĆ']); |
173 | 116 | }); |
174 | 117 | }); |
0 commit comments