|
1 | | -const t = require('../test-lib/test.js'); |
2 | | -const assert = require('assert'); |
| 1 | +const { strict: assert } = require('node:assert'); |
3 | 2 | const _ = require('lodash'); |
| 3 | +const t = require('../test-lib/test.js'); |
4 | 4 |
|
5 | 5 | describe('Docs', function() { |
6 | 6 | const apiKey = 'this is a test api key'; |
@@ -1234,8 +1234,163 @@ describe('Docs', function() { |
1234 | 1234 |
|
1235 | 1235 | }); |
1236 | 1236 |
|
| 1237 | +describe.only('tasks', function () { |
| 1238 | + |
| 1239 | + before(async function() { |
| 1240 | + apos = await t.create({ |
| 1241 | + root: module, |
| 1242 | + modules: { |
| 1243 | + '@apostrophecms/i18n': { |
| 1244 | + options: { |
| 1245 | + locales: { |
| 1246 | + en: {}, |
| 1247 | + fr: { |
| 1248 | + prefix: '/fr' |
| 1249 | + } |
| 1250 | + } |
| 1251 | + } |
| 1252 | + }, |
| 1253 | + 'test-people': { |
| 1254 | + extend: '@apostrophecms/piece-type', |
| 1255 | + fields: { |
| 1256 | + add: { |
| 1257 | + _friends: { |
| 1258 | + type: 'relationship', |
| 1259 | + max: 1, |
| 1260 | + withType: 'test-people', |
| 1261 | + label: 'Friends' |
| 1262 | + } |
| 1263 | + } |
| 1264 | + } |
| 1265 | + }, |
| 1266 | + unlocalized: { |
| 1267 | + extend: '@apostrophecms/piece-type', |
| 1268 | + options: { |
| 1269 | + localized: false |
| 1270 | + }, |
| 1271 | + fields: { |
| 1272 | + add: { |
| 1273 | + _friends: { |
| 1274 | + type: 'relationship', |
| 1275 | + max: 1, |
| 1276 | + withType: 'test-people', |
| 1277 | + label: 'Friends' |
| 1278 | + } |
| 1279 | + } |
| 1280 | + } |
| 1281 | + }, |
| 1282 | + '@apostrophecms/page': { |
| 1283 | + options: { |
| 1284 | + park: [], |
| 1285 | + types: [ |
| 1286 | + { |
| 1287 | + name: 'test-page', |
| 1288 | + label: 'Test Page' |
| 1289 | + } |
| 1290 | + ] |
| 1291 | + } |
| 1292 | + }, |
| 1293 | + 'test-page': { |
| 1294 | + extend: '@apostrophecms/page-type' |
| 1295 | + } |
| 1296 | + |
| 1297 | + } |
| 1298 | + }); |
| 1299 | + }); |
| 1300 | + |
| 1301 | + it('should get the aposDocId when calling @apostrophecms/doc:get-apos-doc-id task with a slug', async function() { |
| 1302 | + await insertPeople(apos); |
| 1303 | + |
| 1304 | + const req = apos.task.getReq(); |
| 1305 | + const doc = await apos.doc.find(req, { |
| 1306 | + type: 'test-people', |
| 1307 | + slug: 'carl' |
| 1308 | + }).toObject(); |
| 1309 | + |
| 1310 | + const actual = await apos.task.invoke( |
| 1311 | + '@apostrophecms/doc:get-apos-doc-id', |
| 1312 | + { |
| 1313 | + slug: doc.slug, |
| 1314 | + locale: 'en' |
| 1315 | + } |
| 1316 | + ); |
| 1317 | + const expected = doc.aposDocId; |
| 1318 | + |
| 1319 | + assert.equal(actual, expected); |
| 1320 | + }); |
| 1321 | + |
| 1322 | + it('should get the aposDocId when calling @apostrophecms/doc:get-apos-doc-id task with an _id', async function() { |
| 1323 | + await insertPeople(apos); |
| 1324 | + |
| 1325 | + const req = apos.task.getReq(); |
| 1326 | + const doc = await apos.doc.find(req, { |
| 1327 | + type: 'test-people', |
| 1328 | + slug: 'carl' |
| 1329 | + }).toObject(); |
| 1330 | + |
| 1331 | + const actual = await apos.task.invoke( |
| 1332 | + '@apostrophecms/doc:get-apos-doc-id', |
| 1333 | + { |
| 1334 | + id: doc._id, |
| 1335 | + locale: 'en' |
| 1336 | + } |
| 1337 | + ); |
| 1338 | + const expected = doc.aposDocId; |
| 1339 | + |
| 1340 | + assert.equal(actual, expected); |
| 1341 | + }); |
| 1342 | +}); |
| 1343 | + |
1237 | 1344 | async function insertPeople(apos) { |
1238 | 1345 | return apos.doc.db.insertMany([ |
| 1346 | + { |
| 1347 | + _id: 'lori:en:draft', |
| 1348 | + aposDocId: 'lori', |
| 1349 | + aposLocale: 'en:draft', |
| 1350 | + slug: 'lori', |
| 1351 | + visibility: 'public', |
| 1352 | + type: 'test-people', |
| 1353 | + firstName: 'Lori', |
| 1354 | + lastName: 'Pizzaroni', |
| 1355 | + age: 32, |
| 1356 | + alive: true |
| 1357 | + }, |
| 1358 | + { |
| 1359 | + _id: 'larry:en:draft', |
| 1360 | + aposDocId: 'larry', |
| 1361 | + aposLocale: 'en:draft', |
| 1362 | + slug: 'larry', |
| 1363 | + visibility: 'public', |
| 1364 | + type: 'test-people', |
| 1365 | + firstName: 'Larry', |
| 1366 | + lastName: 'Cherber', |
| 1367 | + age: 28, |
| 1368 | + alive: true |
| 1369 | + }, |
| 1370 | + { |
| 1371 | + _id: 'carl:en:draft', |
| 1372 | + aposDocId: 'carl', |
| 1373 | + aposLocale: 'en:draft', |
| 1374 | + slug: 'carl', |
| 1375 | + visibility: 'public', |
| 1376 | + type: 'test-people', |
| 1377 | + firstName: 'Carl', |
| 1378 | + lastName: 'Sagan', |
| 1379 | + age: 62, |
| 1380 | + alive: false, |
| 1381 | + friendsIds: [ 'larry' ] |
| 1382 | + }, |
| 1383 | + { |
| 1384 | + _id: 'peter:en:draft', |
| 1385 | + aposDocId: 'peter', |
| 1386 | + aposLocale: 'en:draft', |
| 1387 | + type: 'test-people', |
| 1388 | + visibility: 'loginRequired', |
| 1389 | + firstName: 'Peter', |
| 1390 | + lastName: 'Pan', |
| 1391 | + age: 70, |
| 1392 | + slug: 'peter' |
| 1393 | + }, |
1239 | 1394 | { |
1240 | 1395 | _id: 'lori:en:published', |
1241 | 1396 | aposDocId: 'lori', |
|
0 commit comments