Skip to content
This repository was archived by the owner on Feb 21, 2024. It is now read-only.

Commit de8b04b

Browse files
committed
fix tests
1 parent 9b08abe commit de8b04b

File tree

6 files changed

+15
-29885
lines changed

6 files changed

+15
-29885
lines changed

.nvmrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
16.13.1
1+
18.13.0

_scripts/client.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class Client {
6060
/**
6161
* Init directus client
6262
*/
63-
async init(onItem, filterCollection) {
63+
async init(onItem = item => item, filterCollection = () => true) {
6464
if(this.initDone) {
6565
return;
6666
}
@@ -152,6 +152,7 @@ class Client {
152152
*/
153153
async get11tyCollections(filterCollection) {
154154
const collections = await this.getDirectusCollections()
155+
if(!filterCollection) throw new Error('Missing parameter filterCollection')
155156
return collections
156157
.filter(({schema}) => !!schema)
157158
.filter(filterCollection)

_scripts/client.test.js

+7-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const createClient = require('./client.js')
2-
const { translate } = require('./client.js')
32
const { start, stop } = require('./directus-server/')
43

54
const port = 8056
@@ -8,6 +7,8 @@ const OPTIONS = {
87
}
98
const NUM_COLLECTIONS = 5 // page, post, settings, multilingual, languages
109

10+
jest.setTimeout(20000)
11+
1112
beforeAll(async () => {
1213
return start(port)
1314
})
@@ -62,6 +63,7 @@ describe('API', () => {
6263
expect(page).not.toBeUndefined()
6364
expect(page).toBeInstanceOf(Array)
6465
expect(page.length).toBeGreaterThan(0)
66+
console.log(page)
6567
expect(page[0].text).toBe('Home page')
6668
expect(post).not.toBeUndefined()
6769
expect(post).toBeInstanceOf(Array)
@@ -76,22 +78,10 @@ describe('API', () => {
7678
test('collections', async () => {
7779
})
7880
test('not multilingual', async () => {
79-
const {multilingual} = await client.getCollections()
80-
expect(multilingual.length).toBe(1)
81-
expect(translate(multilingual[0], 'multilingual_translations')).toBeNull()
81+
const {page} = await client.getCollections()
82+
expect(client.translate(page[0], null, 'en-US').lang).toBeUndefined()
8283
})
8384
test('translations', async () => {
84-
client = await createClient({
85-
...OPTIONS,
86-
translationField: 'multilingual_translations',
87-
languageCollection: 'languages',
88-
})
89-
await client.init()
90-
const {multilingual} = await client.getCollections()
91-
expect(multilingual.length).toBe(2) // 1 item in 2 lang
92-
expect(multilingual[0].lang).not.toBeUndefined()
93-
})
94-
test('translate filter', async () => {
9585
client = await createClient({
9686
...OPTIONS,
9787
translationField: 'multilingual_translations',
@@ -100,8 +90,8 @@ describe('API', () => {
10090
await client.init()
10191
const {multilingual} = await client.getCollections()
10292
const item = multilingual[0]
103-
expect(item.translated).toBeUndefined()
104-
const translated = translate(item, 'multilingual_translations')
93+
expect(item.lang).toBeUndefined()
94+
const translated = client.translate(item, 'multilingual_translations', 'en-US')
10595
expect(translated).not.toBeUndefined()
10696
expect(translated.text).not.toBeUndefined()
10797
expect(translated.text.startsWith('text '))

_scripts/directus-server/data.db

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)