<commit_before>// activity-test.js
//
// Test the AS2 conversion module
//
// Copyright 2017 <NAME> <<EMAIL>>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

"use strict";

var assert = require("assert"),
    vows = require("vows"),
    uuid = require("uuid");

var suite = vows.describe("AS2 conversion module interface");

var testVocabConversion = function(verb, newVerb) {
    return {
        topic: function(toAS2) {
            var act = {
                id: "urn:uuid:" + uuid.v4(),
                actor: "acct:evan@w3.example",
                verb: verb,
                to: [{objectType: "collection",
                      id: "http://w3.example/socialwg",
                      links: {
                          "next": "http://w3.example/a/next/url",
                          "prev": "http://w3.example/a/prev/url",
                          "last": "http://w3.example/a/last/url"
                      }}],
                target: {
                    id: "urn:uuid:" + uuid.v4(),
                    objectType: "note"
                }
            };

            toAS2(act, this.callback);
        },
        "type uses AS2 vocabulary": function(act) {
            assert.isFalse(act.hasOwnProperty("verb"));
            assert.equal(act["type"], newVerb);
        }
    };
};

suite.addBatch({
    "When we get the AS2 conversion module": {
        topic: function() {
            return require("../lib/as2");
        },
        "it works": function(err, as2) {
            assert.ifError(err);
            assert.isFunction(as2);
        },
        "and we try to convert a post of a note to AS2": {
            topic: function(as2) {
                var act = {
                    id: "urn:uuid:77451568-ce6a-42eb-8a9f-60ece187725f",
                    actor: "acct:<EMAIL>",
                    verb: "post",
                    title: "I am a title!",
                    upstreamDuplicates: [],
                    downstreamDuplicates: [],
                    to: [{objectType: "collection",
                          id: "http://w3.example/socialwg",
                          links: {
                              "next": "http://w3.example/a/next/url",
                              "prev": "http://w3.example/a/prev/url",
                              "last": "http://w3.example/a/last/url"
                          }}],
                    object: {
                        id: "urn:uuid:33166eb9-2567-477c-ad90-9352dd904712",
                        objectType: "note"
                    },
                    displayName: "<NAME>"
                };

                as2(act, this.callback);
            },
            "it has an @context": function(act) {
                assert.isTrue(act.hasOwnProperty("@context"));
                assert.equal(act["@context"], "https://www.w3.org/ns/activitystreams");
            },
            "the `post` verb is converted specially to Create in type": function(act) {
                assert.isFalse(act.hasOwnProperty("verb"));
                assert.equal(act["type"], "Create");
            },
            "the object's objectType is renamed to type": function(act) {
                assert.isFalse(act.object.hasOwnProperty("objectType"));
                assert.equal(act.object["type"], "Note");
            },
            "the `to` field's collection's objectType is renamed to type": function(act) {
                assert.isFalse(act.to[0].hasOwnProperty("objectType"));
                assert.equal(act.to[0]["type"], "Collection");
            },
            // XXX should we test for all objectType renames? E.g. in the `to` field?
            "displayName is renamed to name": function(act) {
                assert.isFalse(act.hasOwnProperty("displayName"));
                assert.equal(act.name, "A note");
            },
            "title is dropped": function(act) {
                assert.isFalse(act.hasOwnProperty("title"));
            },
            "upstreamDuplicates is dropped": function(act) {
                assert.isFalse(act.hasOwnProperty("upstreamDuplicates"));
            },
            "downstreamDuplicates is dropped": function(act) {
                assert.isFalse(act.hasOwnProperty("downstreamDuplicates"));
            }
        },
        "and we try to convert a post of a note to a collection to AS2": {
            topic: function(as2) {
                var act = {
                    id: "urn:uuid:3738fceb-9705-4fa8-a0d3-59852770dc4d",
                    actor: "acct:<EMAIL>",
                    verb: "post",
                    title: "A rando note I want to categorize",
                    to: [{objectType: "collection",
                          id: "http://w3.example/socialwg",
                          links: {
                              "next": "http://w3.example/a/next/url",
                              "prev": "http://w3.example/a/prev/url",
                              "last": "http://w3.example/a/last/url"
                          }}],
                    object: {
                        id: "urn:uuid:33166eb9-2567-477c-ad90-9352dd904712",
                        objectType: "note"
                    },
                    target: {
                        id: "http://w3.example/chris/a-collection",
                        objectType: "collection"
                    }
                };

                as2(act, this.callback);
            },
            "the `post` verb is converted specially to Add in type": function(act) {
                assert.isFalse(act.hasOwnProperty("verb"));
                assert.equal(act["type"], "Add");
            }
        },
        "and we try to convert a like of a note to AS2": {
            topic: function(as2) {
                var act = {
                    id: "urn:uuid:db8b4174-a321-430f-bbbe-e11c65dd48ee",
                    actor: "acct:<EMAIL>",
                    verb: "like",
                    to: [{objectType: "collection",
                          id: "http://w3.example/socialwg",
                          links: {
                              "next": "http://w3.example/a/next/url",
                              "prev": "http://w3.example/a/prev/url",
                              "last": "http://w3.example/a/last/url"
                          }}],
                    // TODO check that this syntax is correct
                    target: {
                        id: "urn:uuid:77451568-ce6a-42eb-8a9f-60ece187725f",
                        objectType: "note"
                    }
                };

                as2(act, this.callback);
            },
            "verb is renamed to type": function(act) {
                assert.isFalse(act.hasOwnProperty("verb"));
                assert.equal(act["type"], "like");
            },
            "the target's objectType is renamed to type": function(act) {
                assert.isFalse(act.target.hasOwnProperty("objectType"));
                assert.equal(act.target["type"], "Note");
            }
        },<commit_msg>Accept to as a scalar; correct type for like activity<commit_after>// as2-test.js
//
// Test the AS2 conversion module
//
// Copyright 2017 <NAME> <<EMAIL>>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

"use strict";

var assert = require("assert"),
    vows = require("vows"),
    uuid = require("uuid");

var suite = vows.describe("AS2 conversion module interface");

var testVocabConversion = function(verb, newVerb) {
    return {
        topic: function(toAS2) {
            var act = {
                id: "urn:uuid:" + uuid.v4(),
                actor: "acct:<EMAIL>",
                verb: verb,
                to: [{objectType: "collection",
                      id: "http://w3.example/socialwg",
                      links: {
                          "next": "http://w3.example/a/next/url",
                          "prev": "http://w3.example/a/prev/url",
                          "last": "http://w3.example/a/last/url"
                      }}],
                target: {
                    id: "urn:uuid:" + uuid.v4(),
                    objectType: "note"
                }
            };

            toAS2(act, this.callback);
        },
        "type uses AS2 vocabulary": function(act) {
            assert.isFalse(act.hasOwnProperty("verb"));
            assert.equal(act["type"], newVerb);
        }
    };
};

suite.addBatch({
    "When we get the AS2 conversion module": {
        topic: function() {
            return require("../lib/as2");
        },
        "it works": function(err, as2) {
            assert.ifError(err);
            assert.isFunction(as2);
        },
        "and we try to convert a post of a note to AS2": {
            topic: function(as2) {
                var act = {
                    id: "urn:uuid:77451568-ce6a-42eb-8a9f-60ece187725f",
                    actor: "acct:<EMAIL>",
                    verb: "post",
                    title: "I am a title!",
                    upstreamDuplicates: [],
                    downstreamDuplicates: [],
                    to: [{objectType: "collection",
                          id: "http://w3.example/socialwg",
                          links: {
                              "next": "http://w3.example/a/next/url",
                              "prev": "http://w3.example/a/prev/url",
                              "last": "http://w3.example/a/last/url"
                          }}],
                    object: {
                        id: "urn:uuid:33166eb9-2567-477c-ad90-9352dd904712",
                        objectType: "note"
                    },
                    displayName: "<NAME>"
                };

                as2(act, this.callback);
            },
            "it has an @context": function(act) {
                assert.isTrue(act.hasOwnProperty("@context"));
                assert.equal(act["@context"], "https://www.w3.org/ns/activitystreams");
            },
            "the `post` verb is converted specially to Create in type": function(act) {
                assert.isFalse(act.hasOwnProperty("verb"));
                assert.equal(act["type"], "Create");
            },
            "the object's objectType is renamed to type": function(act) {
                assert.isFalse(act.object.hasOwnProperty("objectType"));
                assert.equal(act.object["type"], "Note");
            },
            "the `to` field's collection's objectType is renamed to type": function(act) {
                assert.isObject(act.to);
                assert.isFalse(act.to.hasOwnProperty("objectType"));
                assert.equal(act.to.type, "Collection");
            },
            // XXX should we test for all objectType renames? E.g. in the `to` field?
            "displayName is renamed to name": function(act) {
                assert.isFalse(act.hasOwnProperty("displayName"));
                assert.equal(act.name, "A note");
            },
            "title is dropped": function(act) {
                assert.isFalse(act.hasOwnProperty("title"));
            },
            "upstreamDuplicates is dropped": function(act) {
                assert.isFalse(act.hasOwnProperty("upstreamDuplicates"));
            },
            "downstreamDuplicates is dropped": function(act) {
                assert.isFalse(act.hasOwnProperty("downstreamDuplicates"));
            }
        },
        "and we try to convert a post of a note to a collection to AS2": {
            topic: function(as2) {
                var act = {
                    id: "urn:uuid:3738fceb-9705-4fa8-a0d3-59852770dc4d",
                    actor: "acct:<EMAIL>",
                    verb: "post",
                    title: "A rando note I want to categorize",
                    to: [{objectType: "collection",
                          id: "http://w3.example/socialwg",
                          links: {
                              "next": "http://w3.example/a/next/url",
                              "prev": "http://w3.example/a/prev/url",
                              "last": "http://w3.example/a/last/url"
                          }}],
                    object: {
                        id: "urn:uuid:33166eb9-2567-477c-ad90-9352dd904712",
                        objectType: "note"
                    },
                    target: {
                        id: "http://w3.example/chris/a-collection",
                        objectType: "collection"
                    }
                };

                as2(act, this.callback);
            },
            "the `post` verb is converted specially to Add in type": function(act) {
                assert.isFalse(act.hasOwnProperty("verb"));
                assert.equal(act["type"], "Add");
            }
        },
        "and we try to convert a like of a note to AS2": {
            topic: function(as2) {
                var act = {
                    id: "urn:uuid:db8b4174-a321-430f-bbbe-e11c65dd48ee",
                    actor: "acct:<EMAIL>",
                    verb: "like",
                    to: [{objectType: "collection",
                          id: "http://w3.example/socialwg",
                          links: {
                              "next": "http://w3.example/a/next/url",
                              "prev": "http://w3.example/a/prev/url",
                              "last": "http://w3.example/a/last/url"
                          }}],
                    // TODO check that this syntax is correct
                    target: {
                        id: "urn:uuid:77451568-ce6a-42eb-8a9f-60ece187725f",
                        objectType: "note"
                    }
                };

                as2(act, this.callback);
            },
            "verb is renamed to type": function(act) {
                assert.isFalse(act.hasOwnProperty("verb"));
                assert.equal(act["type"], "Like");
            },
            "the target's objectType is renamed to type": function(act) {
                assert.isFalse(act.target.hasOwnProperty("objectType"));
                assert.equal(act.target["type"], "Note");
            }
        },
{'fraction_non_alphanumeric': 0.13004425070999273, 'fraction_numerical': 0.023512317548378573, 'mean_word_length': 1.2787057938299473, 'pattern_counts': {'":': 58, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4963763', 'n_tokens_mistral': 4265, 'n_tokens_neox': 3977, 'n_words': 888}