How to use mockMatcher method in differencify

Best JavaScript code snippet using differencify

matcher.test.ts

Source:matcher.test.ts Github

copy

Full Screen

...213describe("addNoneOfMatcherUrl", () => {214 it("adds the matcher in the noneOf matchers of the policy", () => {215 const myPolicy = addNoneOfMatcherUrl(216 mockPolicy(MOCKED_POLICY_IRI),217 mockMatcher(MOCKED_MATCHER_IRI)218 );219 expect(getUrlAll(myPolicy, ACP_NONE)).toContain(MOCKED_MATCHER_IRI.value);220 });221 it("does not remove the existing noneOf matchers", () => {222 const mockedPolicy = mockPolicy(MOCKED_POLICY_IRI, {223 noneOf: [mockMatcher(OTHER_MOCKED_MATCHER_IRI)],224 });225 const myPolicy = addNoneOfMatcherUrl(226 mockedPolicy,227 mockMatcher(MOCKED_MATCHER_IRI)228 );229 expect(getUrlAll(myPolicy, ACP_NONE)).toContain(230 OTHER_MOCKED_MATCHER_IRI.value231 );232 });233 it("does not change the existing allOf and anyOf matchers", () => {234 const mockedPolicy = mockPolicy(MOCKED_POLICY_IRI, {235 anyOf: [mockMatcher(ANYOF_MATCHER_IRI)],236 allOf: [mockMatcher(ALLOF_MATCHER_IRI)],237 });238 const myPolicy = addNoneOfMatcherUrl(239 mockedPolicy,240 mockMatcher(NONEOF_MATCHER_IRI)241 );242 expect(getUrlAll(myPolicy, ACP_ALL)).toContain(ALLOF_MATCHER_IRI.value);243 expect(getUrlAll(myPolicy, ACP_ANY)).toContain(ANYOF_MATCHER_IRI.value);244 });245 it("does not change the input policy", () => {246 const myPolicy = mockPolicy(MOCKED_POLICY_IRI);247 const updatedPolicy = addNoneOfMatcherUrl(248 myPolicy,249 mockMatcher(MOCKED_MATCHER_IRI)250 );251 expect(myPolicy).not.toStrictEqual(updatedPolicy);252 });253});254describe("addAnyOfMatcherUrl", () => {255 it("adds the matcher in the anyOf matchers of the policy", () => {256 const myPolicy = addAnyOfMatcherUrl(257 mockPolicy(MOCKED_POLICY_IRI),258 mockMatcher(MOCKED_MATCHER_IRI)259 );260 expect(getUrlAll(myPolicy, ACP_ANY)).toContain(MOCKED_MATCHER_IRI.value);261 });262 it("does not remove the existing anyOf matchers", () => {263 const mockedPolicy = mockPolicy(MOCKED_POLICY_IRI, {264 anyOf: [mockMatcher(OTHER_MOCKED_MATCHER_IRI)],265 });266 const myPolicy = addAnyOfMatcherUrl(267 mockedPolicy,268 mockMatcher(MOCKED_POLICY_IRI)269 );270 expect(getUrlAll(myPolicy, ACP_ANY)).toContain(271 OTHER_MOCKED_MATCHER_IRI.value272 );273 });274 it("does not change the existing allOf and noneOf matchers", () => {275 const mockedPolicy = mockPolicy(MOCKED_POLICY_IRI, {276 noneOf: [mockMatcher(NONEOF_MATCHER_IRI)],277 allOf: [mockMatcher(ALLOF_MATCHER_IRI)],278 });279 const myPolicy = addAnyOfMatcherUrl(280 mockedPolicy,281 mockMatcher(ANYOF_MATCHER_IRI)282 );283 expect(getUrlAll(myPolicy, ACP_ALL)).toContain(ALLOF_MATCHER_IRI.value);284 expect(getUrlAll(myPolicy, ACP_NONE)).toContain(NONEOF_MATCHER_IRI.value);285 });286 it("does not change the input policy", () => {287 const myPolicy = mockPolicy(MOCKED_POLICY_IRI);288 const updatedPolicy = addAnyOfMatcherUrl(289 myPolicy,290 mockMatcher(MOCKED_MATCHER_IRI)291 );292 expect(myPolicy).not.toStrictEqual(updatedPolicy);293 });294});295describe("addAllOfMatcherUrl", () => {296 it("adds the matcher in the allOf matchers of the policy", () => {297 const myPolicy = addAllOfMatcherUrl(298 mockPolicy(MOCKED_POLICY_IRI),299 mockMatcher(MOCKED_MATCHER_IRI)300 );301 expect(getUrlAll(myPolicy, ACP_ALL)).toContain(MOCKED_MATCHER_IRI.value);302 });303 it("does not remove the existing allOf matchers", () => {304 const mockedPolicy = mockPolicy(MOCKED_POLICY_IRI, {305 allOf: [mockMatcher(OTHER_MOCKED_MATCHER_IRI)],306 });307 const myPolicy = addAllOfMatcherUrl(308 mockedPolicy,309 mockMatcher(MOCKED_MATCHER_IRI)310 );311 expect(getUrlAll(myPolicy, ACP_ALL)).toContain(312 OTHER_MOCKED_MATCHER_IRI.value313 );314 });315 it("does not change the existing anyOf and noneOf matchers", () => {316 const mockedPolicy = mockPolicy(MOCKED_POLICY_IRI, {317 noneOf: [mockMatcher(NONEOF_MATCHER_IRI)],318 anyOf: [mockMatcher(ANYOF_MATCHER_IRI)],319 });320 const myPolicy = addAllOfMatcherUrl(321 mockedPolicy,322 mockMatcher(ANYOF_MATCHER_IRI)323 );324 expect(getUrlAll(myPolicy, ACP_ANY)).toContain(ANYOF_MATCHER_IRI.value);325 expect(getUrlAll(myPolicy, ACP_NONE)).toContain(NONEOF_MATCHER_IRI.value);326 });327 it("does not change the input policy", () => {328 const myPolicy = mockPolicy(MOCKED_POLICY_IRI);329 const updatedPolicy = addAnyOfMatcherUrl(330 myPolicy,331 mockMatcher(MOCKED_MATCHER_IRI)332 );333 expect(myPolicy).not.toStrictEqual(updatedPolicy);334 });335});336describe("setNoneOfMatcherUrl", () => {337 it("sets the provided matchers as the noneOf matchers for the policy", () => {338 const myPolicy = setNoneOfMatcherUrl(339 mockPolicy(MOCKED_POLICY_IRI),340 mockMatcher(MOCKED_MATCHER_IRI)341 );342 expect(getUrlAll(myPolicy, ACP_NONE)).toContain(MOCKED_MATCHER_IRI.value);343 });344 it("removes any previous noneOf matchers for on the policy", () => {345 const mockedPolicy = mockPolicy(MOCKED_POLICY_IRI, {346 noneOf: [mockMatcher(OTHER_MOCKED_MATCHER_IRI)],347 });348 const myPolicy = setNoneOfMatcherUrl(349 mockedPolicy,350 mockMatcher(MOCKED_MATCHER_IRI)351 );352 expect(getUrlAll(myPolicy, ACP_NONE)).not.toContain(353 OTHER_MOCKED_MATCHER_IRI.value354 );355 });356 it("does not change the existing anyOf and allOf matchers on the policy", () => {357 const mockedPolicy = mockPolicy(MOCKED_POLICY_IRI, {358 anyOf: [mockMatcher(ANYOF_MATCHER_IRI)],359 allOf: [mockMatcher(ALLOF_MATCHER_IRI)],360 });361 const myPolicy = setNoneOfMatcherUrl(362 mockedPolicy,363 mockMatcher(NONEOF_MATCHER_IRI)364 );365 expect(getUrlAll(myPolicy, ACP_ALL)).toContain(ALLOF_MATCHER_IRI.value);366 expect(getUrlAll(myPolicy, ACP_ANY)).toContain(ANYOF_MATCHER_IRI.value);367 });368 it("does not change the input policy", () => {369 const myPolicy = mockPolicy(MOCKED_POLICY_IRI);370 const updatedPolicy = setNoneOfMatcherUrl(371 myPolicy,372 mockMatcher(MOCKED_MATCHER_IRI)373 );374 expect(myPolicy).not.toStrictEqual(updatedPolicy);375 });376});377describe("setAnyOfMatcherUrl", () => {378 it("sets the provided matchers as the anyOf matchers for the policy", () => {379 const myPolicy = setAnyOfMatcherUrl(380 mockPolicy(MOCKED_POLICY_IRI),381 mockMatcher(MOCKED_MATCHER_IRI)382 );383 expect(getUrlAll(myPolicy, ACP_ANY)).toContain(MOCKED_MATCHER_IRI.value);384 });385 it("removes any previous anyOf matchers for on the policy", () => {386 const mockedPolicy = mockPolicy(MOCKED_POLICY_IRI, {387 anyOf: [mockMatcher(OTHER_MOCKED_MATCHER_IRI)],388 });389 const myPolicy = setAnyOfMatcherUrl(390 mockedPolicy,391 mockMatcher(MOCKED_MATCHER_IRI)392 );393 expect(getUrlAll(myPolicy, ACP_ANY)).not.toContain(394 OTHER_MOCKED_MATCHER_IRI.value395 );396 });397 it("does not change the existing noneOf and allOf matchers on the policy", () => {398 const mockedPolicy = mockPolicy(MOCKED_POLICY_IRI, {399 noneOf: [mockMatcher(NONEOF_MATCHER_IRI)],400 allOf: [mockMatcher(ALLOF_MATCHER_IRI)],401 });402 const myPolicy = setAnyOfMatcherUrl(403 mockedPolicy,404 mockMatcher(ANYOF_MATCHER_IRI)405 );406 expect(getUrlAll(myPolicy, ACP_ALL)).toContain(ALLOF_MATCHER_IRI.value);407 expect(getUrlAll(myPolicy, ACP_NONE)).toContain(NONEOF_MATCHER_IRI.value);408 });409 it("does not change the input policy", () => {410 const myPolicy = mockPolicy(MOCKED_POLICY_IRI);411 const updatedPolicy = setAnyOfMatcherUrl(412 myPolicy,413 mockMatcher(MOCKED_MATCHER_IRI)414 );415 expect(myPolicy).not.toStrictEqual(updatedPolicy);416 });417});418describe("setAllOfMatcherUrl", () => {419 it("sets the provided matchers as the allOf matchers for the policy", () => {420 const myPolicy = setAllOfMatcherUrl(421 mockPolicy(MOCKED_POLICY_IRI),422 mockMatcher(MOCKED_MATCHER_IRI)423 );424 expect(getUrlAll(myPolicy, ACP_ALL)).toContain(MOCKED_MATCHER_IRI.value);425 });426 it("removes any previous allOf matchers for on the policy", () => {427 const mockedPolicy = mockPolicy(MOCKED_POLICY_IRI, {428 allOf: [mockMatcher(OTHER_MOCKED_MATCHER_IRI)],429 });430 const myPolicy = setAllOfMatcherUrl(431 mockedPolicy,432 mockMatcher(MOCKED_MATCHER_IRI)433 );434 expect(getUrlAll(myPolicy, ACP_ALL)).not.toContain(435 OTHER_MOCKED_MATCHER_IRI.value436 );437 });438 it("does not change the existing noneOf and anyOf matchers on the policy", () => {439 const mockedPolicy = mockPolicy(MOCKED_POLICY_IRI, {440 noneOf: [mockMatcher(NONEOF_MATCHER_IRI)],441 anyOf: [mockMatcher(ANYOF_MATCHER_IRI)],442 });443 const myPolicy = setAllOfMatcherUrl(444 mockedPolicy,445 mockMatcher(ALLOF_MATCHER_IRI)446 );447 expect(getUrlAll(myPolicy, ACP_ANY)).toContain(ANYOF_MATCHER_IRI.value);448 expect(getUrlAll(myPolicy, ACP_NONE)).toContain(NONEOF_MATCHER_IRI.value);449 });450 it("does not change the input policy", () => {451 const myPolicy = mockPolicy(MOCKED_POLICY_IRI);452 const updatedPolicy = setAllOfMatcherUrl(453 myPolicy,454 mockMatcher(MOCKED_MATCHER_IRI)455 );456 expect(myPolicy).not.toStrictEqual(updatedPolicy);457 });458});459describe("getNoneOfMatcherUrlAll", () => {460 it("returns all the noneOf matchers for the given policy", () => {461 const mockedPolicy = mockPolicy(MOCKED_POLICY_IRI, {462 noneOf: [463 mockMatcher(MOCKED_MATCHER_IRI),464 mockMatcher(OTHER_MOCKED_MATCHER_IRI),465 ],466 });467 const noneOfMatchers = getNoneOfMatcherUrlAll(mockedPolicy);468 expect(noneOfMatchers).toContain(MOCKED_MATCHER_IRI.value);469 expect(noneOfMatchers).toContain(OTHER_MOCKED_MATCHER_IRI.value);470 expect(noneOfMatchers).toHaveLength(2);471 });472 it("returns only the noneOf matchers for the given policy", () => {473 const mockedPolicy = mockPolicy(MOCKED_POLICY_IRI, {474 noneOf: [mockMatcher(NONEOF_MATCHER_IRI)],475 anyOf: [mockMatcher(ANYOF_MATCHER_IRI)],476 allOf: [mockMatcher(ALLOF_MATCHER_IRI)],477 });478 const noneOfMatchers = getNoneOfMatcherUrlAll(mockedPolicy);479 expect(noneOfMatchers).not.toContain(ANYOF_MATCHER_IRI.value);480 expect(noneOfMatchers).not.toContain(ALLOF_MATCHER_IRI.value);481 expect(noneOfMatchers).toHaveLength(1);482 });483});484describe("getAnyOfMatcherUrlAll", () => {485 it("returns all the anyOf matchers for the given policy", () => {486 const mockedPolicy = mockPolicy(MOCKED_POLICY_IRI, {487 anyOf: [488 mockMatcher(MOCKED_MATCHER_IRI),489 mockMatcher(OTHER_MOCKED_MATCHER_IRI),490 ],491 });492 const anyOfMatchers = getAnyOfMatcherUrlAll(mockedPolicy);493 expect(anyOfMatchers).toContain(MOCKED_MATCHER_IRI.value);494 expect(anyOfMatchers).toContain(OTHER_MOCKED_MATCHER_IRI.value);495 expect(anyOfMatchers).toHaveLength(2);496 });497 it("returns only the anyOf matchers for the given policy", () => {498 const mockedPolicy = mockPolicy(MOCKED_POLICY_IRI, {499 noneOf: [mockMatcher(NONEOF_MATCHER_IRI)],500 anyOf: [mockMatcher(ANYOF_MATCHER_IRI)],501 allOf: [mockMatcher(ALLOF_MATCHER_IRI)],502 });503 const anyOfMatchers = getAnyOfMatcherUrlAll(mockedPolicy);504 expect(anyOfMatchers).not.toContain(NONEOF_MATCHER_IRI.value);505 expect(anyOfMatchers).not.toContain(ALLOF_MATCHER_IRI.value);506 expect(anyOfMatchers).toHaveLength(1);507 });508});509describe("getAllOfMatcherUrlAll", () => {510 it("returns all the allOf matchers for the given policy", () => {511 const mockedPolicy = mockPolicy(MOCKED_POLICY_IRI, {512 allOf: [513 mockMatcher(MOCKED_MATCHER_IRI),514 mockMatcher(OTHER_MOCKED_MATCHER_IRI),515 ],516 });517 const allOfMatchers = getAllOfMatcherUrlAll(mockedPolicy);518 expect(allOfMatchers).toContain(MOCKED_MATCHER_IRI.value);519 expect(allOfMatchers).toContain(OTHER_MOCKED_MATCHER_IRI.value);520 expect(allOfMatchers).toHaveLength(2);521 });522 it("returns only the allOf matchers for the given policy", () => {523 const mockedPolicy = mockPolicy(MOCKED_POLICY_IRI, {524 noneOf: [mockMatcher(NONEOF_MATCHER_IRI)],525 anyOf: [mockMatcher(ANYOF_MATCHER_IRI)],526 allOf: [mockMatcher(ALLOF_MATCHER_IRI)],527 });528 const allOfMatchers = getAllOfMatcherUrlAll(mockedPolicy);529 expect(allOfMatchers).not.toContain(NONEOF_MATCHER_IRI.value);530 expect(allOfMatchers).not.toContain(ANYOF_MATCHER_IRI.value);531 expect(allOfMatchers).toHaveLength(1);532 });533});534describe("removeAllOfMatcherUrl", () => {535 it("removes the matcher from the allOf matchers for the given policy", () => {536 const mockedMatcher = mockMatcher(MOCKED_MATCHER_IRI);537 const mockedPolicy = mockPolicy(MOCKED_POLICY_IRI, {538 allOf: [mockedMatcher],539 });540 const result = removeAllOfMatcherUrl(mockedPolicy, mockedMatcher);541 expect(getUrlAll(result, ACP_ALL)).not.toContain(MOCKED_MATCHER_IRI.value);542 });543 it("does not remove the matcher from the anyOf/noneOf matchers for the given policy", () => {544 const mockedMatcher = mockMatcher(MOCKED_MATCHER_IRI);545 const mockedPolicy = mockPolicy(MOCKED_POLICY_IRI, {546 anyOf: [mockedMatcher],547 noneOf: [mockedMatcher],548 });549 const result = removeAllOfMatcherUrl(mockedPolicy, mockedMatcher);550 expect(getUrlAll(result, ACP_ANY)).toContain(MOCKED_MATCHER_IRI.value);551 expect(getUrlAll(result, ACP_NONE)).toContain(MOCKED_MATCHER_IRI.value);552 });553});554describe("removeAnyOfMatcherUrl", () => {555 it("removes the matcher from the allOf matchers for the given policy", () => {556 const mockedMatcher = mockMatcher(MOCKED_MATCHER_IRI);557 const mockedPolicy = mockPolicy(MOCKED_POLICY_IRI, {558 anyOf: [mockedMatcher],559 });560 const result = removeAnyOfMatcherUrl(mockedPolicy, mockedMatcher);561 expect(getUrlAll(result, ACP_ANY)).not.toContain(MOCKED_MATCHER_IRI.value);562 });563 it("does not remove the matcher from the allOf/noneOf matchers for the given policy", () => {564 const mockedMatcher = mockMatcher(MOCKED_MATCHER_IRI);565 const mockedPolicy = mockPolicy(MOCKED_POLICY_IRI, {566 allOf: [mockedMatcher],567 noneOf: [mockedMatcher],568 });569 const result = removeAnyOfMatcherUrl(mockedPolicy, mockedMatcher);570 expect(getUrlAll(result, ACP_ALL)).toContain(MOCKED_MATCHER_IRI.value);571 expect(getUrlAll(result, ACP_NONE)).toContain(MOCKED_MATCHER_IRI.value);572 });573});574describe("removeNoneOfMatcherUrl", () => {575 it("removes the matcher from the noneOf matchers for the given policy", () => {576 const mockedMatcher = mockMatcher(MOCKED_MATCHER_IRI);577 const mockedPolicy = mockPolicy(MOCKED_POLICY_IRI, {578 noneOf: [mockedMatcher],579 });580 const result = removeNoneOfMatcherUrl(mockedPolicy, mockedMatcher);581 expect(getUrlAll(result, ACP_NONE)).not.toContain(MOCKED_MATCHER_IRI.value);582 });583 it("does not remove the matcher from the allOf/anyOf matchers for the given policy", () => {584 const mockedMatcher = mockMatcher(MOCKED_MATCHER_IRI);585 const mockedPolicy = mockPolicy(MOCKED_POLICY_IRI, {586 allOf: [mockedMatcher],587 anyOf: [mockedMatcher],588 });589 const result = removeNoneOfMatcherUrl(mockedPolicy, mockedMatcher);590 expect(getUrlAll(result, ACP_ALL)).toContain(MOCKED_MATCHER_IRI.value);591 expect(getUrlAll(result, ACP_ANY)).toContain(MOCKED_MATCHER_IRI.value);592 });593});594describe("createMatcher", () => {595 it("returns a acp:Matcher", () => {596 const myMatcher = createMatcher(MOCKED_MATCHER_IRI.value);597 expect(getUrl(myMatcher, RDF_TYPE)).toBe(ACP_MATCHER.value);598 });599 it("returns an **empty** matcher", () => {600 const myMatcher = createMatcher("https://my.pod/matcher-resource#matcher");601 // The matcher should only contain a type triple.602 expect(Object.keys(myMatcher.predicates)).toHaveLength(1);603 });604});605describe("createResourceMatcherFor", () => {606 it("returns a acp:Matcher", () => {607 const mockedAcr = mockAcrFor("https://some.pod/resource");608 const mockedResourceWithAcr = addMockAcrTo(609 mockSolidDatasetFrom("https://some.pod/resource"),610 mockedAcr611 );612 const myMatcher = createResourceMatcherFor(613 mockedResourceWithAcr,614 "myMatcher"615 );616 expect(getIri(myMatcher, RDF_TYPE)).toBe(ACP_MATCHER.value);617 });618 it("returns an **empty** matcher", () => {619 const mockedAcr = mockAcrFor("https://some.pod/resource");620 const mockedResourceWithAcr = addMockAcrTo(621 mockSolidDatasetFrom("https://some.pod/resource"),622 mockedAcr623 );624 const myMatcher = createResourceMatcherFor(625 mockedResourceWithAcr,626 "myMatcher"627 );628 // The matcher should only contain a type triple.629 expect(Object.keys(myMatcher.predicates)).toHaveLength(1);630 });631});632describe("getMatcher", () => {633 it("returns the matcher with a matching IRI", () => {634 const matcher = mockMatcher(MOCKED_MATCHER_IRI);635 const dataset = setThing(createSolidDataset(), matcher);636 const result = getMatcher(dataset, MOCKED_MATCHER_IRI.value);637 expect(result).not.toBeNull();638 });639 it("does not return a Thing with a matching IRI but the wrong type", () => {640 const notAMatcher = createThing({641 url: "https://my.pod/matcher-resource#not-a-matcher",642 });643 const dataset = setThing(644 createSolidDataset(),645 setUrl(notAMatcher, RDF_TYPE, "http://example.org/ns#NotMatcherType")646 );647 const result = getMatcher(648 dataset,649 "https://my.pod/matcher-resource#not-a-matcher"650 );651 expect(result).toBeNull();652 });653 it("does not return a matcher with a mismatching IRI", () => {654 const matcher = mockMatcher(MOCKED_MATCHER_IRI);655 const dataset = setThing(createSolidDataset(), matcher);656 const result = getMatcher(dataset, OTHER_MOCKED_MATCHER_IRI);657 expect(result).toBeNull();658 });659});660describe("getResourceMatcher", () => {661 it("returns the matcher with a matching name", () => {662 let mockedAcr = mockAcrFor("https://some.pod/resource");663 let mockedMatcher = createThing({664 url: `${getSourceUrl(mockedAcr)}#matcher`,665 });666 mockedMatcher = setUrl(mockedMatcher, rdf.type, acp.Matcher);667 mockedAcr = setThing(mockedAcr, mockedMatcher);668 const mockedResourceWithAcr = addMockAcrTo(669 mockSolidDatasetFrom("https://some.pod/resource"),670 mockedAcr671 );672 const result = getResourceMatcher(mockedResourceWithAcr, "matcher");673 expect(result).not.toBeNull();674 });675 it("does not return a Thing with a matching IRI but the wrong type", () => {676 let mockedAcr = mockAcrFor("https://some.pod/resource");677 let mockedMatcher = createThing({678 url: `${getSourceUrl(mockedAcr)}#matcher`,679 });680 mockedMatcher = setUrl(681 mockedMatcher,682 rdf.type,683 "http://example.org/ns#NotMatcherType"684 );685 mockedAcr = setThing(mockedAcr, mockedMatcher);686 const mockedResourceWithAcr = addMockAcrTo(687 mockSolidDatasetFrom("https://some.pod/resource"),688 mockedAcr689 );690 const result = getResourceMatcher(mockedResourceWithAcr, "matcher");691 expect(result).toBeNull();692 });693 it("does not return a matcher with a mismatching IRI", () => {694 let mockedAcr = mockAcrFor("https://some.pod/resource");695 let mockedMatcher = createThing({696 url: `${getSourceUrl(mockedAcr)}#matcher`,697 });698 mockedMatcher = setUrl(mockedMatcher, rdf.type, acp.Matcher);699 mockedAcr = setThing(mockedAcr, mockedMatcher);700 const mockedResourceWithAcr = addMockAcrTo(701 mockSolidDatasetFrom("https://some.pod/resource"),702 mockedAcr703 );704 const result = getResourceMatcher(mockedResourceWithAcr, "other-matcher");705 expect(result).toBeNull();706 });707});708describe("getMatcherAll", () => {709 it("returns an empty array if there are no matchers in the given Dataset", () => {710 expect(getMatcherAll(createSolidDataset())).toHaveLength(0);711 });712 it("returns all the matchers in a matcher resource", () => {713 const matcher = mockMatcher(MOCKED_MATCHER_IRI);714 const dataset = setThing(createSolidDataset(), matcher);715 let result = getMatcherAll(dataset);716 expect(result).toHaveLength(1);717 const anotherMatcher = mockMatcher(OTHER_MOCKED_MATCHER_IRI);718 const newDataset = setThing(dataset, anotherMatcher);719 result = getMatcherAll(newDataset);720 expect(result).toHaveLength(2);721 });722});723describe("getResourceMatcherAll", () => {724 it("returns an empty array if there are no matchers in the given Resource's ACR", () => {725 const mockedAcr = mockAcrFor("https://some.pod/resource");726 const mockedResourceWithAcr = addMockAcrTo(727 mockSolidDatasetFrom("https://some.pod/resource"),728 mockedAcr729 );730 expect(getResourceMatcherAll(mockedResourceWithAcr)).toHaveLength(0);731 });732 it("returns all the matchers in a Resource's ACR", () => {733 let mockedAcr = mockAcrFor("https://some.pod/resource");734 let mockedMatcher1 = createThing({735 url: `${getSourceUrl(mockedAcr)}#matcher1`,736 });737 mockedMatcher1 = setUrl(mockedMatcher1, rdf.type, acp.Matcher);738 let mockedMatcher2 = createThing({739 url: `${getSourceUrl(mockedAcr)}#matcher2`,740 });741 mockedMatcher2 = setUrl(mockedMatcher2, rdf.type, acp.Matcher);742 mockedAcr = setThing(mockedAcr, mockedMatcher1);743 mockedAcr = setThing(mockedAcr, mockedMatcher2);744 const mockedResourceWithAcr = addMockAcrTo(745 mockSolidDatasetFrom("https://some.pod/resource"),746 mockedAcr747 );748 const result = getResourceMatcherAll(mockedResourceWithAcr);749 expect(result).toHaveLength(2);750 });751});752describe("removeMatcher", () => {753 it("removes the matcher from the given empty Dataset", () => {754 const matcher = mockMatcher(MOCKED_MATCHER_IRI);755 const dataset = setThing(createSolidDataset(), matcher);756 const updatedDataset = removeMatcher(dataset, MOCKED_MATCHER_IRI);757 expect(getThingAll(updatedDataset)).toHaveLength(0);758 });759});760describe("removeResourceMatcher", () => {761 it("removes the matcher from the given Resource's Access control Resource", () => {762 let mockedAcr = mockAcrFor("https://some.pod/resource");763 let mockedMatcher = createThing({764 url: `${getSourceUrl(mockedAcr)}#matcher`,765 });766 mockedMatcher = setUrl(mockedMatcher, rdf.type, acp.Matcher);767 mockedAcr = setThing(mockedAcr, mockedMatcher);768 const mockedResourceWithAcr = addMockAcrTo(769 mockSolidDatasetFrom("https://some.pod/resource"),770 mockedAcr771 );772 const updatedDataset = removeResourceMatcher(773 mockedResourceWithAcr,774 mockedMatcher775 );776 expect(getResourceMatcherAll(updatedDataset)).toHaveLength(0);777 });778 it("accepts a plain name to remove a matcher", () => {779 let mockedAcr = mockAcrFor("https://some.pod/resource");780 let mockedMatcher = createThing({781 url: `${getSourceUrl(mockedAcr)}#matcher`,782 });783 mockedMatcher = setUrl(mockedMatcher, rdf.type, acp.Matcher);784 mockedAcr = setThing(mockedAcr, mockedMatcher);785 const mockedResourceWithAcr = addMockAcrTo(786 mockSolidDatasetFrom("https://some.pod/resource"),787 mockedAcr788 );789 const updatedDataset = removeResourceMatcher(790 mockedResourceWithAcr,791 "matcher"792 );793 expect(getResourceMatcherAll(updatedDataset)).toHaveLength(0);794 });795 it("accepts a full URL to remove a matcher", () => {796 let mockedAcr = mockAcrFor("https://some.pod/resource");797 let mockedMatcher = createThing({798 url: `${getSourceUrl(mockedAcr)}#matcher`,799 });800 mockedMatcher = setUrl(mockedMatcher, rdf.type, acp.Matcher);801 mockedAcr = setThing(mockedAcr, mockedMatcher);802 const mockedResourceWithAcr = addMockAcrTo(803 mockSolidDatasetFrom("https://some.pod/resource"),804 mockedAcr805 );806 const updatedDataset = removeResourceMatcher(807 mockedResourceWithAcr,808 `${getSourceUrl(mockedAcr)}#matcher`809 );810 expect(getResourceMatcherAll(updatedDataset)).toHaveLength(0);811 });812 it("accepts a Named Node to remove a matcher", () => {813 let mockedAcr = mockAcrFor("https://some.pod/resource");814 let mockedMatcher = createThing({815 url: `${getSourceUrl(mockedAcr)}#matcher`,816 });817 mockedMatcher = setUrl(mockedMatcher, rdf.type, acp.Matcher);818 mockedAcr = setThing(mockedAcr, mockedMatcher);819 const mockedResourceWithAcr = addMockAcrTo(820 mockSolidDatasetFrom("https://some.pod/resource"),821 mockedAcr822 );823 const updatedDataset = removeResourceMatcher(824 mockedResourceWithAcr,825 DataFactory.namedNode(`${getSourceUrl(mockedAcr)}#matcher`)826 );827 expect(getResourceMatcherAll(updatedDataset)).toHaveLength(0);828 });829 it("does not remove a non-matcher with the same name", () => {830 let mockedAcr = mockAcrFor("https://some.pod/resource");831 let mockedMatcher = createThing({832 url: `${getSourceUrl(mockedAcr)}#matcher`,833 });834 mockedMatcher = setUrl(835 mockedMatcher,836 rdf.type,837 "https://example.vocab/not-a-matcher"838 );839 mockedAcr = setThing(mockedAcr, mockedMatcher);840 const mockedResourceWithAcr = addMockAcrTo(841 mockSolidDatasetFrom("https://some.pod/resource"),842 mockedAcr843 );844 const updatedDataset = removeResourceMatcher(845 mockedResourceWithAcr,846 "matcher"847 );848 const updatedAcr = internal_getAcr(updatedDataset);849 expect(850 getThing(updatedAcr, `${getSourceUrl(mockedAcr)}#matcher`)851 ).not.toBeNull();852 });853});854describe("setMatcher", () => {855 it("sets the matcher in the given empty Dataset", () => {856 const matcher = mockMatcher(MOCKED_MATCHER_IRI);857 const dataset = setMatcher(createSolidDataset(), matcher);858 const result = getThing(dataset, MOCKED_MATCHER_IRI);859 expect(result).not.toBeNull();860 expect(getIriAll(result as Thing, rdf.type)).toContain(acp.Matcher);861 });862});863describe("setResourceMatcher", () => {864 it("sets the matcher in the given Resource's ACR", () => {865 const mockedAcr = mockAcrFor("https://some.pod/resource");866 const mockedResourceWithAcr = addMockAcrTo(867 mockSolidDatasetFrom("https://some.pod/resource"),868 mockedAcr869 );870 let mockedMatcher = createThing({871 url: `${getSourceUrl(mockedAcr)}#matcher`,872 });873 mockedMatcher = setUrl(mockedMatcher, rdf.type, acp.Matcher);874 const updatedResource = setResourceMatcher(875 mockedResourceWithAcr,876 mockedMatcher877 );878 expect(getResourceMatcherAll(updatedResource)).toHaveLength(1);879 });880});881describe("getAgentAll", () => {882 it("returns all the agents a matcher applies to by WebID", () => {883 const matcher = mockMatcher(MOCKED_MATCHER_IRI, {884 agents: [MOCK_WEBID_ME, MOCK_WEBID_YOU],885 });886 const agents = getAgentAll(matcher);887 expect(agents).toContain(MOCK_WEBID_ME.value);888 expect(agents).toContain(MOCK_WEBID_YOU.value);889 expect(agents).toHaveLength(2);890 });891 it("does not return the public/authenticated/creator/clients a matcher applies to", () => {892 const matcher = mockMatcher(MOCKED_MATCHER_IRI, {893 public: true,894 authenticated: true,895 creator: true,896 clients: [MOCK_CLIENT_IDENTIFIER_1],897 });898 const agents = getAgentAll(matcher);899 expect(agents).not.toContain(ACP_CREATOR.value);900 expect(agents).not.toContain(ACP_AUTHENTICATED.value);901 expect(agents).not.toContain(ACP_PUBLIC.value);902 expect(agents).toHaveLength(0);903 });904});905describe("setAgent", () => {906 it("sets the given agents for the matcher", () => {907 const matcher = mockMatcher(MOCKED_MATCHER_IRI);908 const result = setAgent(matcher, MOCK_WEBID_ME.value);909 expect(getUrlAll(result, ACP_AGENT)).toContain(MOCK_WEBID_ME.value);910 });911 it("deletes any agents previously set for the matcher", () => {912 const matcher = mockMatcher(MOCKED_MATCHER_IRI, {913 agents: [MOCK_WEBID_YOU],914 });915 const result = setAgent(matcher, MOCK_WEBID_ME.value);916 expect(getUrlAll(result, ACP_AGENT)).toContain(MOCK_WEBID_ME.value);917 expect(getUrlAll(result, ACP_AGENT)).not.toContain(MOCK_WEBID_YOU.value);918 });919 it("does not change the input matcher", () => {920 const matcher = mockMatcher(MOCKED_MATCHER_IRI, {921 agents: [MOCK_WEBID_YOU],922 });923 setAgent(matcher, MOCK_WEBID_ME.value);924 expect(getUrlAll(matcher, ACP_AGENT)).not.toContain(MOCK_WEBID_ME.value);925 expect(getUrlAll(matcher, ACP_AGENT)).toContain(MOCK_WEBID_YOU.value);926 });927 it("does not overwrite public, authenticated and creator agents", () => {928 const matcher = mockMatcher(MOCKED_MATCHER_IRI, {929 public: true,930 authenticated: true,931 creator: true,932 });933 const result = setAgent(matcher, MOCK_WEBID_YOU.value);934 expect(getUrlAll(result, ACP_AGENT)).toContain(ACP_PUBLIC.value);935 expect(getUrlAll(result, ACP_AGENT)).toContain(ACP_AUTHENTICATED.value);936 expect(getUrlAll(result, ACP_AGENT)).toContain(ACP_CREATOR.value);937 });938});939describe("addAgent", () => {940 it("adds the given agent to the matcher", () => {941 const matcher = mockMatcher(MOCKED_MATCHER_IRI);942 const result = addAgent(matcher, MOCK_WEBID_YOU.value);943 expect(getUrlAll(result, ACP_AGENT)).toContain(MOCK_WEBID_YOU.value);944 });945 it("does not override existing agents/public/authenticated", () => {946 const matcher = mockMatcher(MOCKED_MATCHER_IRI, {947 agents: [MOCK_WEBID_ME],948 public: true,949 authenticated: true,950 });951 const result = addAgent(matcher, MOCK_WEBID_YOU.value);952 expect(getUrlAll(result, ACP_AGENT)).toContain(MOCK_WEBID_ME.value);953 expect(getUrlAll(result, ACP_AGENT)).toContain(MOCK_WEBID_YOU.value);954 expect(getUrlAll(result, ACP_AGENT)).toContain(ACP_PUBLIC.value);955 expect(getUrlAll(result, ACP_AGENT)).toContain(ACP_AUTHENTICATED.value);956 });957});958describe("removeAgent", () => {959 it("removes the given agent from the matcher", () => {960 const matcher = mockMatcher(MOCKED_MATCHER_IRI, {961 agents: [MOCK_WEBID_YOU],962 });963 const result = removeAgent(matcher, MOCK_WEBID_YOU.value);964 expect(getUrlAll(result, ACP_AGENT)).not.toContain(MOCK_WEBID_YOU.value);965 });966 it("does not delete unrelated agents", () => {967 const matcher = mockMatcher(MOCKED_MATCHER_IRI, {968 agents: [MOCK_WEBID_ME, MOCK_WEBID_YOU],969 public: true,970 authenticated: true,971 });972 const result = removeAgent(matcher, MOCK_WEBID_YOU.value);973 expect(getUrlAll(result, ACP_AGENT)).not.toContain(MOCK_WEBID_YOU.value);974 expect(getUrlAll(result, ACP_AGENT)).toContain(MOCK_WEBID_ME.value);975 expect(getUrlAll(result, ACP_AGENT)).toContain(ACP_PUBLIC.value);976 expect(getUrlAll(result, ACP_AGENT)).toContain(ACP_AUTHENTICATED.value);977 });978});979describe("hasPublic", () => {980 it("returns true if the matcher applies to the public agent", () => {981 const matcher = mockMatcher(MOCKED_MATCHER_IRI, {982 public: true,983 });984 expect(hasPublic(matcher)).toBe(true);985 });986 it("returns false if the matcher only applies to other agent", () => {987 const matcher = mockMatcher(MOCKED_MATCHER_IRI, {988 public: false,989 authenticated: true,990 agents: [MOCK_WEBID_ME],991 });992 expect(hasPublic(matcher)).toBe(false);993 });994});995describe("setPublic", () => {996 it("applies the given matcher to the public agent", () => {997 const matcher = mockMatcher(MOCKED_MATCHER_IRI);998 const result = setPublic(matcher);999 expect(getUrlAll(result, ACP_AGENT)).toContain(ACP_PUBLIC.value);1000 });1001 it("does not change the input matcher", () => {1002 const matcher = mockMatcher(MOCKED_MATCHER_IRI);1003 setPublic(matcher);1004 expect(getUrlAll(matcher, ACP_AGENT)).not.toContain(ACP_PUBLIC.value);1005 });1006 it("does not change the other agents", () => {1007 const matcher = mockMatcher(MOCKED_MATCHER_IRI, {1008 authenticated: true,1009 agents: [MOCK_WEBID_ME],1010 });1011 const result = setPublic(matcher);1012 expect(getUrlAll(result, ACP_AGENT)).toContain(ACP_AUTHENTICATED.value);1013 expect(getUrlAll(result, ACP_AGENT)).toContain(MOCK_WEBID_ME.value);1014 });1015 it("throws an error when you attempt to use the deprecated API", () => {1016 const matcher = mockMatcher(MOCKED_MATCHER_IRI);1017 expect(1018 // @ts-expect-error The type signature should warn about passing a second argument:1019 () => setPublic(matcher, true)1020 ).toThrow(1021 "The function `setPublic` no longer takes a second parameter. It is now used together with `removePublic` instead."1022 );1023 });1024});1025describe("removePublic", () => {1026 it("prevents the matcher from applying to the public agent", () => {1027 const matcher = mockMatcher(MOCKED_MATCHER_IRI, {1028 public: true,1029 });1030 const result = removePublic(matcher);1031 expect(getUrlAll(result, ACP_AGENT)).not.toContain(ACP_PUBLIC.value);1032 });1033 it("does not change the input matcher", () => {1034 const matcher = mockMatcher(MOCKED_MATCHER_IRI, { public: true });1035 removePublic(matcher);1036 expect(getUrlAll(matcher, ACP_AGENT)).toContain(ACP_PUBLIC.value);1037 });1038 it("does not change the other agents", () => {1039 const matcher = mockMatcher(MOCKED_MATCHER_IRI, {1040 authenticated: true,1041 agents: [MOCK_WEBID_ME],1042 public: true,1043 });1044 const result = removePublic(matcher);1045 expect(getUrlAll(result, ACP_AGENT)).toContain(ACP_AUTHENTICATED.value);1046 expect(getUrlAll(result, ACP_AGENT)).toContain(MOCK_WEBID_ME.value);1047 });1048});1049describe("hasAuthenticated", () => {1050 it("returns true if the matcher applies to authenticated agents", () => {1051 const matcher = mockMatcher(MOCKED_MATCHER_IRI, {1052 authenticated: true,1053 });1054 expect(hasAuthenticated(matcher)).toBe(true);1055 });1056 it("returns false if the matcher only applies to other agent", () => {1057 const matcher = mockMatcher(MOCKED_MATCHER_IRI, {1058 public: true,1059 authenticated: false,1060 agents: [MOCK_WEBID_ME],1061 });1062 expect(hasAuthenticated(matcher)).toBe(false);1063 });1064});1065describe("setAuthenticated", () => {1066 it("applies to given matcher to authenticated agents", () => {1067 const matcher = mockMatcher(MOCKED_MATCHER_IRI);1068 const result = setAuthenticated(matcher);1069 expect(getUrlAll(result, ACP_AGENT)).toContain(ACP_AUTHENTICATED.value);1070 });1071 it("does not change the input matcher", () => {1072 const matcher = mockMatcher(MOCKED_MATCHER_IRI);1073 setAuthenticated(matcher);1074 expect(getUrlAll(matcher, ACP_AGENT)).not.toContain(1075 ACP_AUTHENTICATED.value1076 );1077 });1078 it("does not change the other agents", () => {1079 const matcher = mockMatcher(MOCKED_MATCHER_IRI, {1080 public: true,1081 agents: [MOCK_WEBID_ME],1082 });1083 const result = setAuthenticated(matcher);1084 expect(getUrlAll(result, ACP_AGENT)).toContain(ACP_PUBLIC.value);1085 expect(getUrlAll(result, ACP_AGENT)).toContain(MOCK_WEBID_ME.value);1086 });1087 it("throws an error when you attempt to use the deprecated API", () => {1088 const matcher = mockMatcher(MOCKED_MATCHER_IRI);1089 expect(1090 // @ts-expect-error The type signature should warn about passing a second argument:1091 () => setAuthenticated(matcher, true)1092 ).toThrow(1093 "The function `setAuthenticated` no longer takes a second parameter. It is now used together with `removeAuthenticated` instead."1094 );1095 });1096});1097describe("removeAuthenticated", () => {1098 it("prevents the matcher from applying to authenticated agents", () => {1099 const matcher = mockMatcher(MOCKED_MATCHER_IRI, {1100 authenticated: true,1101 });1102 const result = removeAuthenticated(matcher);1103 expect(getUrlAll(result, ACP_AGENT)).not.toContain(ACP_AUTHENTICATED.value);1104 });1105 it("does not change the input matcher", () => {1106 const matcher = mockMatcher(MOCKED_MATCHER_IRI, { authenticated: true });1107 removeAuthenticated(matcher);1108 expect(getUrlAll(matcher, ACP_AGENT)).toContain(ACP_AUTHENTICATED.value);1109 });1110 it("does not change the other agents", () => {1111 const matcher = mockMatcher(MOCKED_MATCHER_IRI, {1112 public: true,1113 authenticated: true,1114 agents: [MOCK_WEBID_ME],1115 });1116 const result = removeAuthenticated(matcher);1117 expect(getUrlAll(result, ACP_AGENT)).toContain(ACP_PUBLIC.value);1118 expect(getUrlAll(result, ACP_AGENT)).toContain(MOCK_WEBID_ME.value);1119 });1120});1121describe("hasCreator", () => {1122 it("returns true if the matcher applies to the Resource's creator", () => {1123 const matcher = mockMatcher(MOCKED_MATCHER_IRI, {1124 creator: true,1125 });1126 expect(hasCreator(matcher)).toBe(true);1127 });1128 it("returns false if the matcher only applies to other agents", () => {1129 const matcher = mockMatcher(MOCKED_MATCHER_IRI, {1130 public: true,1131 creator: false,1132 agents: [MOCK_WEBID_ME],1133 });1134 expect(hasCreator(matcher)).toBe(false);1135 });1136});1137describe("setCreator", () => {1138 it("applies the given matcher to the Resource's creator", () => {1139 const matcher = mockMatcher(MOCKED_MATCHER_IRI);1140 const result = setCreator(matcher);1141 expect(getUrlAll(result, ACP_AGENT)).toContain(ACP_CREATOR.value);1142 });1143 it("does not change the input matcher", () => {1144 const matcher = mockMatcher(MOCKED_MATCHER_IRI);1145 setCreator(matcher);1146 expect(getUrlAll(matcher, ACP_AGENT)).not.toContain(ACP_CREATOR.value);1147 });1148 it("does not change the other agents", () => {1149 const matcher = mockMatcher(MOCKED_MATCHER_IRI, {1150 public: true,1151 agents: [MOCK_WEBID_ME],1152 });1153 const result = setCreator(matcher);1154 expect(getUrlAll(result, ACP_AGENT)).toContain(ACP_PUBLIC.value);1155 expect(getUrlAll(result, ACP_AGENT)).toContain(MOCK_WEBID_ME.value);1156 });1157 it("throws an error when you attempt to use the deprecated API", () => {1158 const matcher = mockMatcher(MOCKED_MATCHER_IRI);1159 expect(1160 // @ts-expect-error The type signature should warn about passing a second argument:1161 () => setCreator(matcher, true)1162 ).toThrow(1163 "The function `setCreator` no longer takes a second parameter. It is now used together with `removeCreator` instead."1164 );1165 });1166});1167describe("removeCreator", () => {1168 it("prevents the matcher from applying to the Resource's creator", () => {1169 const matcher = mockMatcher(MOCKED_MATCHER_IRI, {1170 creator: true,1171 });1172 const result = removeCreator(matcher);1173 expect(getUrlAll(result, ACP_AGENT)).not.toContain(ACP_CREATOR.value);1174 });1175 it("does not change the input matcher", () => {1176 const matcher = mockMatcher(MOCKED_MATCHER_IRI, { creator: true });1177 removeCreator(matcher);1178 expect(getUrlAll(matcher, ACP_AGENT)).toContain(ACP_CREATOR.value);1179 });1180 it("does not change the other agents", () => {1181 const matcher = mockMatcher(MOCKED_MATCHER_IRI, {1182 creator: true,1183 public: true,1184 agents: [MOCK_WEBID_ME],1185 });1186 const result = removeCreator(matcher);1187 expect(getUrlAll(result, ACP_AGENT)).toContain(ACP_PUBLIC.value);1188 expect(getUrlAll(result, ACP_AGENT)).toContain(MOCK_WEBID_ME.value);1189 });1190});1191describe("getClientAll", () => {1192 it("returns all the clients a matcher applies to by WebID", () => {1193 const matcher = mockMatcher(MOCKED_MATCHER_IRI, {1194 clients: [1195 MOCK_CLIENT_IDENTIFIER_1,1196 MOCK_CLIENT_IDENTIFIER_2,1197 MOCK_CLIENT_ID_3,1198 ],1199 });1200 const clients = getClientAll(matcher);1201 expect(clients).toContain(MOCK_CLIENT_IDENTIFIER_1.value);1202 expect(clients).toContain(MOCK_CLIENT_IDENTIFIER_2.value);1203 expect(clients).toContain(MOCK_CLIENT_ID_3);1204 expect(clients).toHaveLength(3);1205 });1206 it("does not return the agents/public client a matcher applies to", () => {1207 const matcher = mockMatcher(MOCKED_MATCHER_IRI, {1208 agents: [MOCK_WEBID_ME],1209 public: true,1210 authenticated: true,1211 creator: true,1212 publicClient: true,1213 });1214 const clients = getClientAll(matcher);1215 expect(clients).not.toContain(ACP_CREATOR.value);1216 expect(clients).not.toContain(ACP_AUTHENTICATED.value);1217 expect(clients).not.toContain(ACP_PUBLIC.value);1218 expect(clients).toHaveLength(0);1219 });1220});1221describe("setClient", () => {1222 it("sets the given clients for the matcher", () => {1223 const matcher = mockMatcher(MOCKED_MATCHER_IRI);1224 const result = setClient(matcher, MOCK_CLIENT_IDENTIFIER_1.value);1225 expect(getUrlAll(result, ACP_CLIENT)).toContain(1226 MOCK_CLIENT_IDENTIFIER_1.value1227 );1228 });1229 it("deletes any clients previously set for the matcher", () => {1230 const matcher = mockMatcher(MOCKED_MATCHER_IRI, {1231 clients: [MOCK_CLIENT_IDENTIFIER_1],1232 });1233 const result = setClient(matcher, MOCK_CLIENT_IDENTIFIER_2.value);1234 expect(getUrlAll(result, ACP_CLIENT)).toContain(1235 MOCK_CLIENT_IDENTIFIER_2.value1236 );1237 expect(getUrlAll(result, ACP_CLIENT)).not.toContain(1238 MOCK_CLIENT_IDENTIFIER_1.value1239 );1240 });1241 it("does not change the input matcher", () => {1242 const matcher = mockMatcher(MOCKED_MATCHER_IRI, {1243 clients: [MOCK_CLIENT_IDENTIFIER_1],1244 });1245 setClient(matcher, MOCK_CLIENT_IDENTIFIER_2.value);1246 expect(getUrlAll(matcher, ACP_CLIENT)).not.toContain(1247 MOCK_CLIENT_IDENTIFIER_2.value1248 );1249 expect(getUrlAll(matcher, ACP_CLIENT)).toContain(1250 MOCK_CLIENT_IDENTIFIER_1.value1251 );1252 });1253 it("does not overwrite the public client class", () => {1254 const matcher = mockMatcher(MOCKED_MATCHER_IRI, {1255 publicClient: true,1256 });1257 const result = setClient(matcher, MOCK_CLIENT_IDENTIFIER_1.value);1258 expect(getUrlAll(result, ACP_CLIENT)).toContain(SOLID_PUBLIC_CLIENT.value);1259 });1260});1261describe("addClient", () => {1262 it("adds the given client to the matcher", () => {1263 const matcher = mockMatcher(MOCKED_MATCHER_IRI);1264 const result = addClient(matcher, MOCK_CLIENT_IDENTIFIER_1.value);1265 expect(getUrlAll(result, ACP_CLIENT)).toContain(1266 MOCK_CLIENT_IDENTIFIER_1.value1267 );1268 });1269 it("adds the given string client ID to the matcher", () => {1270 const matcher = mockMatcher(MOCKED_MATCHER_IRI);1271 const result = addClient(matcher, MOCK_CLIENT_ID_3);1272 expect(getStringNoLocaleAll(result, ACP_CLIENT)).toContain(1273 MOCK_CLIENT_ID_31274 );1275 });1276 it("does not override existing clients/the public client class", () => {1277 const matcher = mockMatcher(MOCKED_MATCHER_IRI, {1278 clients: [MOCK_CLIENT_IDENTIFIER_1],1279 publicClient: true,1280 });1281 const result = addClient(matcher, MOCK_CLIENT_IDENTIFIER_2.value);1282 expect(getUrlAll(result, ACP_CLIENT)).toContain(1283 MOCK_CLIENT_IDENTIFIER_1.value1284 );1285 expect(getUrlAll(result, ACP_CLIENT)).toContain(1286 MOCK_CLIENT_IDENTIFIER_2.value1287 );1288 expect(getUrlAll(result, ACP_CLIENT)).toContain(SOLID_PUBLIC_CLIENT.value);1289 });1290});1291describe("removeClient", () => {1292 it("removes the given client from the matcher", () => {1293 const matcher = mockMatcher(MOCKED_MATCHER_IRI, {1294 clients: [MOCK_CLIENT_IDENTIFIER_1, MOCK_CLIENT_IDENTIFIER_2],1295 });1296 const result = removeClient(matcher, MOCK_CLIENT_IDENTIFIER_1.value);1297 expect(getUrlAll(result, ACP_CLIENT)).not.toContain(1298 MOCK_CLIENT_IDENTIFIER_1.value1299 );1300 expect(getUrlAll(result, ACP_CLIENT)).toContain(1301 MOCK_CLIENT_IDENTIFIER_2.value1302 );1303 });1304 it("removes the given string client ID from the matcher", () => {1305 const matcher = mockMatcher(MOCKED_MATCHER_IRI, {1306 clients: [MOCK_CLIENT_ID_3, MOCK_CLIENT_ID_4],1307 });1308 const result = removeClient(matcher, MOCK_CLIENT_ID_3);1309 expect(getStringNoLocaleAll(result, ACP_CLIENT)).not.toContain(1310 MOCK_CLIENT_ID_31311 );1312 expect(getStringNoLocaleAll(result, ACP_CLIENT)).toContain(1313 MOCK_CLIENT_ID_41314 );1315 });1316 it("does not delete unrelated clients", () => {1317 const matcher = mockMatcher(MOCKED_MATCHER_IRI, {1318 clients: [MOCK_CLIENT_IDENTIFIER_1, MOCK_CLIENT_IDENTIFIER_2],1319 publicClient: true,1320 });1321 const result = removeClient(matcher, MOCK_CLIENT_IDENTIFIER_2.value);1322 expect(getUrlAll(result, ACP_CLIENT)).not.toContain(1323 MOCK_CLIENT_IDENTIFIER_2.value1324 );1325 expect(getUrlAll(result, ACP_CLIENT)).toContain(1326 MOCK_CLIENT_IDENTIFIER_1.value1327 );1328 expect(getUrlAll(result, ACP_CLIENT)).toContain(SOLID_PUBLIC_CLIENT.value);1329 });1330 it("does not remove agents, even with a matching IRI", () => {1331 const matcher = mockMatcher(MOCKED_MATCHER_IRI, {1332 agents: [MOCK_WEBID_ME],1333 });1334 const result = removeClient(matcher, MOCK_WEBID_ME.value);1335 expect(getUrlAll(result, ACP_AGENT)).toContain(MOCK_WEBID_ME.value);1336 });1337});1338describe("hasAnyClient", () => {1339 it("returns true if the matcher applies to any client", () => {1340 const matcher = mockMatcher(MOCKED_MATCHER_IRI, {1341 publicClient: true,1342 });1343 expect(hasAnyClient(matcher)).toBe(true);1344 });1345 it("returns false if the matcher only applies to individual clients", () => {1346 const matcher = mockMatcher(MOCKED_MATCHER_IRI, {1347 clients: [MOCK_CLIENT_IDENTIFIER_1],1348 });1349 expect(hasAnyClient(matcher)).toBe(false);1350 });1351});1352describe("setAnyClient", () => {1353 it("applies to given matcher to the public client class", () => {1354 const matcher = mockMatcher(MOCKED_MATCHER_IRI);1355 const result = setAnyClient(matcher);1356 expect(getUrlAll(result, ACP_CLIENT)).toContain(SOLID_PUBLIC_CLIENT.value);1357 });1358 it("does not change the input matcher", () => {1359 const matcher = mockMatcher(MOCKED_MATCHER_IRI);1360 setAnyClient(matcher);1361 expect(getUrlAll(matcher, ACP_CLIENT)).not.toContain(1362 SOLID_PUBLIC_CLIENT.value1363 );1364 });1365 it("does not change the other clients", () => {1366 const matcher = mockMatcher(MOCKED_MATCHER_IRI, {1367 clients: [MOCK_CLIENT_IDENTIFIER_1],1368 });1369 const result = setAnyClient(matcher);1370 expect(getUrlAll(result, ACP_CLIENT)).toContain(1371 MOCK_CLIENT_IDENTIFIER_1.value1372 );1373 });1374});1375describe("removeAnyClient", () => {1376 it("prevents the matcher from applying to the public client class", () => {1377 const matcher = mockMatcher(MOCKED_MATCHER_IRI, {1378 publicClient: true,1379 });1380 const result = removeAnyClient(matcher);1381 expect(getUrlAll(result, ACP_CLIENT)).not.toContain(1382 SOLID_PUBLIC_CLIENT.value1383 );1384 });1385 it("does not change the input matcher", () => {1386 const matcher = mockMatcher(MOCKED_MATCHER_IRI, { publicClient: true });1387 removeAnyClient(matcher);1388 expect(getUrlAll(matcher, ACP_CLIENT)).toContain(SOLID_PUBLIC_CLIENT.value);1389 });1390 it("does not change the other clients", () => {1391 const matcher = mockMatcher(MOCKED_MATCHER_IRI, {1392 publicClient: true,1393 clients: [MOCK_CLIENT_IDENTIFIER_1],1394 });1395 const result = removeAnyClient(matcher);1396 expect(getUrlAll(result, ACP_CLIENT)).toContain(1397 MOCK_CLIENT_IDENTIFIER_1.value1398 );1399 });1400});1401describe("matcherAsMarkdown", () => {1402 it("shows when a matcher is empty", () => {1403 const matcher = createMatcher("https://some.pod/policyResource#matcher");1404 expect(matcherAsMarkdown(matcher)).toBe(1405 "## Matcher: https://some.pod/policyResource#matcher\n" +...

Full Screen

Full Screen

cachingmatcher_test.js

Source:cachingmatcher_test.js Github

copy

Full Screen

1// Copyright 2013 The Closure Library Authors. All Rights Reserved.2//3// Licensed under the Apache License, Version 2.0 (the "License");4// you may not use this file except in compliance with the License.5// You may obtain a copy of the License at6//7// http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// distributed under the License is distributed on an "AS-IS" BASIS,11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12// See the License for the specific language governing permissions and13// limitations under the License.14goog.provide('goog.ui.ac.CachingMatcherTest');15goog.setTestOnly('goog.ui.ac.CachingMatcherTest');16goog.require('goog.testing.MockControl');17goog.require('goog.testing.jsunit');18goog.require('goog.testing.mockmatchers');19goog.require('goog.ui.ac.CachingMatcher');20ignoreArgument = goog.testing.mockmatchers.ignoreArgument;21/**22 * Fake version of Throttle which only fires when we call permitOne().23 * @constructor24 * @suppress {missingProvide}25 */26goog.async.Throttle = function(fn, time, self) {27 this.fn = fn;28 this.time = time;29 this.self = self;30 this.numFires = 0;31};32/** @suppress {missingProvide} */33goog.async.Throttle.prototype.fire = function() {34 this.numFires++;35};36/** @suppress {missingProvide} */37goog.async.Throttle.prototype.permitOne = function() {38 if (this.numFires == 0) {39 return;40 }41 this.fn.call(this.self);42 this.numFires = 0;43};44// Actual tests.45var mockControl;46var mockMatcher;47var mockHandler;48var matcher;49function setUp() {50 mockControl = new goog.testing.MockControl();51 mockMatcher = {52 requestMatchingRows: mockControl.createFunctionMock('requestMatchingRows')53 };54 mockHandler = mockControl.createFunctionMock('matchHandler');55 matcher = new goog.ui.ac.CachingMatcher(mockMatcher);56}57function tearDown() {58 mockControl.$tearDown();59}60function testLocalThenRemoteMatch() {61 // We immediately get the local match.62 mockHandler('foo', []);63 mockControl.$replayAll();64 matcher.requestMatchingRows('foo', 12, mockHandler);65 mockControl.$verifyAll();66 mockControl.$resetAll();67 // Now we run the remote match.68 mockHandler('foo', ['foo1', 'foo2'], ignoreArgument);69 mockMatcher.requestMatchingRows('foo', 100, ignoreArgument)70 .$does(function(token, maxResults, matchHandler) {71 matchHandler('foo', ['foo1', 'foo2', 'bar3']);72 });73 mockControl.$replayAll();74 matcher.throttledTriggerBaseMatch_.permitOne();75 mockControl.$verifyAll();76 mockControl.$resetAll();77}78function testCacheSize() {79 matcher.setMaxCacheSize(4);80 // First we populate, but not overflow the cache.81 mockHandler('foo', []);82 mockHandler('foo', ['foo111', 'foo222'], ignoreArgument);83 mockMatcher.requestMatchingRows('foo', 100, ignoreArgument)84 .$does(function(token, maxResults, matchHandler) {85 matchHandler('foo', ['foo111', 'foo222', 'bar333']);86 });87 mockControl.$replayAll();88 matcher.requestMatchingRows('foo', 12, mockHandler);89 matcher.throttledTriggerBaseMatch_.permitOne();90 mockControl.$verifyAll();91 mockControl.$resetAll();92 // Now we verify the cache is populated.93 mockHandler('foo1', ['foo111']);94 mockControl.$replayAll();95 matcher.requestMatchingRows('foo1', 12, mockHandler);96 mockControl.$verifyAll();97 mockControl.$resetAll();98 // Now we overflow the cache. Check that the remote results show the first99 // time we get them back, even though they overflow the cache.100 mockHandler('foo11', ['foo111']);101 mockHandler(102 'foo11', ['foo111', 'foo112', 'foo113', 'foo114'], ignoreArgument);103 mockMatcher.requestMatchingRows('foo11', 100, ignoreArgument)104 .$does(function(token, maxResults, matchHandler) {105 matchHandler('foo11', ['foo111', 'foo112', 'foo113', 'foo114']);106 });107 mockControl.$replayAll();108 matcher.requestMatchingRows('foo11', 12, mockHandler);109 matcher.throttledTriggerBaseMatch_.permitOne();110 mockControl.$verifyAll();111 mockControl.$resetAll();112 // Now check that the cache is empty.113 mockHandler('foo11', []);114 mockControl.$replayAll();115 matcher.requestMatchingRows('foo11', 12, mockHandler);116 mockControl.$verifyAll();117 mockControl.$resetAll();118}119function testSimilarMatchingDoesntReorderResults() {120 // Populate the cache. We get two prefix matches.121 mockHandler('ba', []);122 mockHandler('ba', ['bar', 'baz', 'bam'], ignoreArgument);123 mockMatcher.requestMatchingRows('ba', 100, ignoreArgument)124 .$does(function(token, maxResults, matchHandler) {125 matchHandler('ba', ['bar', 'baz', 'bam']);126 });127 mockControl.$replayAll();128 matcher.requestMatchingRows('ba', 12, mockHandler);129 matcher.throttledTriggerBaseMatch_.permitOne();130 mockControl.$verifyAll();131 mockControl.$resetAll();132 // The user types another character. The local match gives us two similar133 // matches, but no prefix matches. The remote match returns a prefix match,134 // which would normally be ranked above the similar matches, but gets ranked135 // below the similar matches because the user hasn't typed any more136 // characters.137 mockHandler('bad', ['bar', 'baz', 'bam']);138 mockHandler(139 'bad', ['bar', 'baz', 'bam', 'bad', 'badder', 'baddest'], ignoreArgument);140 mockMatcher.requestMatchingRows('bad', 100, ignoreArgument)141 .$does(function(token, maxResults, matchHandler) {142 matchHandler('bad', ['bad', 'badder', 'baddest']);143 });144 mockControl.$replayAll();145 matcher.requestMatchingRows('bad', 12, mockHandler);146 matcher.throttledTriggerBaseMatch_.permitOne();147 mockControl.$verifyAll();148 mockControl.$resetAll();149 // The user types yet another character, which allows the prefix matches to150 // jump to the top of the list of suggestions.151 mockHandler('badd', ['badder', 'baddest']);152 mockControl.$replayAll();153 matcher.requestMatchingRows('badd', 12, mockHandler);154 mockControl.$verifyAll();155 mockControl.$resetAll();156}157function testSetThrottleTime() {158 assertEquals(150, matcher.throttledTriggerBaseMatch_.time);159 matcher.setThrottleTime(234);160 assertEquals(234, matcher.throttledTriggerBaseMatch_.time);161}162function testSetBaseMatcherMaxMatches() {163 mockHandler('foo', []); // Local match164 mockMatcher.requestMatchingRows('foo', 789, ignoreArgument);165 mockControl.$replayAll();166 matcher.setBaseMatcherMaxMatches();167 matcher.requestMatchingRows('foo', 12, mockHandler);168}169function testSetLocalMatcher() {170 // Use a local matcher which just sorts all the rows alphabetically.171 function sillyMatcher(token, maxMatches, rows) {172 rows = rows.concat([]);173 rows.sort();174 return rows;175 }176 mockHandler('foo', []);177 mockHandler('foo', ['a', 'b', 'c'], ignoreArgument);178 mockMatcher.requestMatchingRows('foo', 100, ignoreArgument)179 .$does(function(token, maxResults, matchHandler) {180 matchHandler('foo', ['b', 'a', 'c']);181 });182 mockControl.$replayAll();183 matcher.setLocalMatcher(sillyMatcher);184 matcher.requestMatchingRows('foo', 12, mockHandler);185 matcher.throttledTriggerBaseMatch_.permitOne();186 mockControl.$verifyAll();187 mockControl.$resetAll();...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { toMatchImageSnapshot } = require('jest-image-snapshot');2expect.extend({ toMatchImageSnapshot });3const { mockMatcher } = require('differencify');4expect.extend({ toMatchImageSnapshot: mockMatcher });5const { toMatchImageSnapshot } = require('jest-image-snapshot');6expect.extend({ toMatchImageSnapshot });7const { mockMatcher } = require('differencify');8expect.extend({ toMatchImageSnapshot: mockMatcher });9const { mockMatcher } = require('differencify');10expect.extend({ toMatchImageSnapshot: mockMatcher });11const { mockMatcher } = require('differencify');12expect.extend({ toMatchImageSnapshot: mockMatcher });13const { toMatchImageSnapshot } = require('jest-image-snapshot');14expect.extend({ toMatchImageSnapshot });15const { mockMatcher } = require('differencify');16expect.extend({ toMatchImageSnapshot: mockMatcher });17const { mockMatcher } = require('differencify');18expect.extend({ toMatchImageSnapshot: mockMatcher });19const { toMatchImageSnapshot } = require('jest-image-snapshot');20expect.extend({ toMatchImageSnapshot });21const { mockMatcher } = require('differencify');22expect.extend({ toMatchImageSnapshot: mockMatcher });23const { toMatchImageSnapshot } = require('jest-image-snapshot');24expect.extend({ toMatchImageSnapshot });25const { mockMatcher } = require('differencify');26expect.extend({ toMatchImageSnapshot: mockMatcher });27const { mockMatcher } = require('differencify');28expect.extend({ toMatchImageSnapshot: mockMatcher });29const { toMatchImageSnapshot } = require('jest-image-snapshot');30expect.extend({ toMatchImageSnapshot });31const { mockMatcher } = require('differencify');32expect.extend({ toMatchImageSnapshot: mockMatcher });33const { mockMatcher } =

Full Screen

Using AI Code Generation

copy

Full Screen

1const { toMatchImageSnapshot } = require('differencify');2expect.extend({ toMatchImageSnapshot });3test('should match', async () => {4 const page = await browser.newPage();5 const image = await page.screenshot();6 expect(image).toMatchImageSnapshot();7});8const { toMatchImageSnapshot } = require('jest-image-snapshot');9expect.extend({ toMatchImageSnapshot });10test('should match', async () => {11 const page = await browser.newPage();12 const image = await page.screenshot();13 expect(image).toMatchImageSnapshot();14});15const { toMatchImageSnapshot } = require('jest-image-snapshot');16expect.extend({ toMatchImageSnapshot });17test('should match', async () => {18 const page = await browser.newPage();19 const image = await page.screenshot();20 expect(image).toMatchImageSnapshot({21 customDiffConfig: {22 },23 });24});25const { toMatchImageSnapshot } = require('differencify');26expect.extend({ toMatchImageSnapshot });27test('should match', async () => {28 const page = await browser.newPage();29 const image = await page.screenshot();30 expect(image).toMatchImageSnapshot({31 customDiffConfig: {32 },33 });34});35const { toMatchImageSnapshot } = require('differencify');36expect.extend({ toMatchImageSnapshot });37test('should match', async () => {38 const page = await browser.newPage();39 const image = await page.screenshot();40 expect(image).toMatchImage

Full Screen

Using AI Code Generation

copy

Full Screen

1const { toMatchImageSnapshot } = require('jest-image-snapshot');2expect.extend({ toMatchImageSnapshot });3describe('test', () => {4 it('test', async () => {5 const image = await page.screenshot();6 expect(image).toMatchImageSnapshot({7 });8 });9});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { toMatchImageSnapshot } = require('differencify');2expect.extend({ toMatchImageSnapshot });3const { toMatchImageSnapshot } = require('differencify');4expect.extend({ toMatchImageSnapshot });5const { toMatchImageSnapshot } = require('differencify');6expect.extend({ toMatchImageSnapshot });7const { toMatchImageSnapshot } = require('differencify');8expect.extend({ toMatchImageSnapshot });9const { toMatchImageSnapshot } = require('differencify');10expect.extend({ toMatchImageSnapshot });11const { toMatchImageSnapshot } = require('differencify');12expect.extend({ toMatchImageSnapshot });13const { toMatchImageSnapshot } = require('differencify');14expect.extend({ toMatchImageSnapshot });15const { toMatchImageSnapshot } = require('differencify');16expect.extend({ toMatchImageSnapshot });17const { toMatchImageSnapshot } = require('differencify');18expect.extend({ toMatchImageSnapshot });19const { toMatchImageSnapshot } = require('differencify');20expect.extend({ toMatchImage

Full Screen

Using AI Code Generation

copy

Full Screen

1const { toMatchImageSnapshot } = require('jest-image-snapshot');2expect.extend({ toMatchImageSnapshot });3const differencify = require('differencify');4const { mockMatcher } = differencify;5expect.extend({ toMatchImageSnapshot: mockMatcher });6expect('some image').toMatchImageSnapshot();7expect('some image').toMatchImageSnapshot({8 customDiffConfig: { threshold: 0.01 },9 chrome: {10 },11 firefox: {12 },13 safari: {14 },

Full Screen

Using AI Code Generation

copy

Full Screen

1require('differencify')({2 matcher: require('differencify').mockMatcher3});4require('differencify')({5 matcher: require('differencify').mockMatcher6});7require('differencify')({8 matcher: require('differencify').mockMatcher9});10require('differencify')({11 matcher: require('differencify').mockMatcher12});13require('differencify')({14 matcher: require('differencify').mockMatcher15});16require('differencify')({17 matcher: require('differencify').mockMatcher18});19require('differencify')({20 matcher: require('differencify').mockMatcher21});22require('differencify')({23 matcher: require('differencify').mockMatcher24});25require('differencify')({26 matcher: require('differencify').mockMatcher27});28require('differencify')({29 matcher: require('differencify').mockMatcher30});31require('differencify')({32 matcher: require('differencify').mockMatcher33});34require('differencify')({35 matcher: require('differencify').mockMatcher36});37require('differencify')({38 matcher: require('differencify').mockMatcher39});40require('differencify')({41 matcher: require('differencify').mockMatcher42});43require('differencify')({44 matcher: require('differencify').mockMatcher45});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { mockMatcher } from 'differencify'2const mockMatcher = require('differencify').mockMatcher3const mockMatcher = require('differencify').mockMatcher4const { mockMatcher } = require('differencify')5const mockMatcher = require('differencify').mockMatcher6const mockMatcher = require('differencify').mockMatcher7const { mockMatcher } = require('differencify')8const mockMatcher = require('differencify').mockMatcher9const mockMatcher = require('differencify').mockMatcher10const { mockMatcher } = require('differencify')11const mockMatcher = require('differencify').mockMatcher12const mockMatcher = require('differencify').mockMatcher13const { mockMatcher } = require('differencify')14const mockMatcher = require('differencify').mockMatcher15const mockMatcher = require('differencify').mockMatcher16const { mockMatcher } = require('differencify')17const mockMatcher = require('differencify').mockMatcher18const mockMatcher = require('differencify').mockMatcher19const { mockMatcher } = require('differencify')20const mockMatcher = require('differencify').mock

Full Screen

Using AI Code Generation

copy

Full Screen

1const differencify = require('differencify')2const { mockMatcher } = differencify3mockMatcher('test', (a, b) => {4})5it('should test', async () => {6 await expect('test').toMatchImageSnapshot({7 })8})9unmockMatcher('test')10it('should test', async () => {11 await expect('test').toMatchImageSnapshot()12})13unmockAllMatchers()14it('should test', async () => {15 await expect('test').toMatchImageSnapshot({16 matcher: (screenshot, baseline) => {17 }18 })19})20type MatchImageSnapshotOptions = {

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run differencify automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful