<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mateusz Wojczal on Medium]]></title>
        <description><![CDATA[Stories by Mateusz Wojczal on Medium]]></description>
        <link>https://medium.com/@mateusz-wojczal?source=rss-684cabb8f247------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Qj2fw1-Yt-VVuA53EwwTgQ.jpeg</url>
            <title>Stories by Mateusz Wojczal on Medium</title>
            <link>https://medium.com/@mateusz-wojczal?source=rss-684cabb8f247------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 12:16:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mateusz-wojczal/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Testowanie Automatyczne w JavaScript —  teoria i przykłady]]></title>
            <link>https://mateusz-wojczal.medium.com/testowanie-automatyczne-w-javascript-teoria-i-przyk%C5%82ady-81193dd023b9?source=rss-684cabb8f247------2</link>
            <guid isPermaLink="false">https://medium.com/p/81193dd023b9</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[test-automation]]></category>
            <category><![CDATA[test-driven-development]]></category>
            <dc:creator><![CDATA[Mateusz Wojczal]]></dc:creator>
            <pubDate>Thu, 26 Nov 2020 10:58:37 GMT</pubDate>
            <atom:updated>2020-11-26T11:05:33.643Z</atom:updated>
            <content:encoded><![CDATA[<h3>Testowanie Automatyczne w JavaScript — teoria i przykłady</h3><p>Testowanie Automatyczne i JavaScript.</p><p>Poniższy post jest dopełnieniem dwóch prezentacji dotyczących Testowania Automatycznego w JavaScript.</p><p>Oczym mówię i koduje:<br>👉 Testy <strong>Jednostkowe</strong> — <a href="https://www.linkedin.com/feed/hashtag/?keywords=jest&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A6737475007003324416">#Jest</a><br>👉 Testy <strong>Strukturalne</strong> i ich konfiguracja, z użyciem narzędzi <a href="https://www.linkedin.com/feed/hashtag/?keywords=codeclimate&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A6737475007003324416">#codeclimate</a> <a href="https://www.linkedin.com/feed/hashtag/?keywords=eslint&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A6737475007003324416">#eslint</a><br>👉 Testy <strong>Integracyjne</strong>/funkcjonalne-jest i <a href="https://www.linkedin.com/feed/hashtag/?keywords=react&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A6737475007003324416">#react</a>-testing-library<br>👉 Testy <strong>End-to-end</strong> e2d — <a href="https://www.linkedin.com/feed/hashtag/?keywords=cypress&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A6737475007003324416">#cypress</a>.js<br>👉 Testy <strong>Akceptacyjne</strong> <a href="https://www.linkedin.com/feed/hashtag/?keywords=codecept&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A6737475007003324416">#codecept</a>.ja<br>👉 Konfiguracja <a href="https://www.linkedin.com/feed/hashtag/?keywords=jest&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A6737475007003324416">#Jest</a> do Test Driven Development, raporty Code Coverage <a href="https://www.linkedin.com/feed/hashtag/?keywords=junit&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A6737475007003324416">#junit</a><br>👉 Konfiguracja Continuous Integration na podstawie <a href="https://www.linkedin.com/feed/hashtag/?keywords=circleci&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A6737475007003324416">#CircleCi</a>, <a href="https://www.linkedin.com/feed/hashtag/?keywords=jest&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A6737475007003324416">#Jest</a> i <a href="https://www.linkedin.com/feed/hashtag/?keywords=cypress&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A6737475007003324416">#Cypress</a><br>👉 Ustawienia pre-hooków z użyciem husky, aby nie wypychać niepoprawnego kodu.</p><p>Oprócz poniższego postu całość dostępna jest w formie repozytorium <a href="https://github.com/qunabu/js-testing-types">github</a> oraz prezentacji wideo:</p><h3>Cześć pierwsza — teoria</h3><p>https://lnkd.in/eTX-KzX</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FU5kcUhzskjY%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DU5kcUhzskjY&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FU5kcUhzskjY%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/95d840db8902f48a932e038942b2178d/href">https://medium.com/media/95d840db8902f48a932e038942b2178d/href</a></iframe><h3>Cześć druga — Livecoding</h3><p><a href="https://www.youtube.com/watch?v=tjo_oJm6pJU">https://www.youtube.com/watch?v=tjo_oJm6pJU</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Ftjo_oJm6pJU%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dtjo_oJm6pJU&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Ftjo_oJm6pJU%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/cedb900bb2c656f2fc4e2475d9c4fa93/href">https://medium.com/media/cedb900bb2c656f2fc4e2475d9c4fa93/href</a></iframe><h3>Testowanie Automatyczne w JavaScript — teoria i przykłady</h3><figure><img alt="Mateusz Wojczal i wsparcie Strajku Kobiet" src="https://cdn-images-1.medium.com/max/301/0*24Haj517zYLwEO_R.png" /></figure><blockquote><em>Pisanie testów to wykrywanie błędów przez programistów w trakcie pisania kodu źródłowego zamiast w najgorszym możliwym momencie czy wykryciu błędu na produkcji przez klienta.</em></blockquote><blockquote>Mateusz Wojczal 2020</blockquote><h3>Typy testów</h3><p>Nie ma jasnego podziału typów testów. Często są mylone grupy i typy. Oprócz podziału na uruchamiane ręczne lub automatyczne są jeszcze:</p><ul><li>Strukturalne - testy białej skrzynki, skupiają się tylko i wyłącznie na testowaniu kodu bądź systemu. Są one przeciwieństwem testów czarnej skrzynki.</li><li>Niefunkcjonalne - testowanie atrybutów modułu lub systemu, które nie odnoszą się do jego funkcjonalności, np. niezawodności, efektywności, pielęgnowalności i przenaszalności.</li><li>Funkcjonalne - testy czarnej skrzynki, oparte na analizie specyfikacji funkcjonalnej modułu lub systemu.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*gbrt-Pc0PMpjQq2s17xoxw.png" /></figure><p>plus Testy <strong>Regresji, </strong><strong>Wizualne (</strong><strong>snapshots)</strong> i inne.</p><h4>Testy jednostkowe</h4><p>Testy jednostkowe są przeprowadzane na bardzo niskim poziomie aplikacji, bardzo zbliżonym do kodu źródłowego oprogramowania i polegają na testowaniu poszczególnych metod i funkcji klas, komponentów lub modułów wykorzystywanych w programie. Automatyzacja jest prosta i mogą one być bardzo szybko przeprowadzane przez serwer ciągłej integracji (jednocześnie).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8f75190de9643e66ae9b2626121bf179/href">https://medium.com/media/8f75190de9643e66ae9b2626121bf179/href</a></iframe><p>Pokrycie kodu określa które części (linie kodu) programu zostały przetestowane przez testy jednostkowe.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gIOwCgUPEHM168fU" /><figcaption>Jest Code Coverage. Procentowe pokrycie kodu</figcaption></figure><p>Pokrycie kodu bardzo dobrze współpracuje z Continuous Integration</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eYGgC7_no37RyE1Q" /><figcaption>Fragmenty kodu bez pokrycia testami. Gitlab</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/0*oaD_Au5ncKTzx0q8" /><figcaption>Rezultat działa statycznej analizy kodu. Narzędzie Code Climate. Gitlab</figcaption></figure><p>Pokrycie kodu bardzo dobrze współpracuje z Continuous Integration. Raport HTML jUnit</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vBJRY4t1vevz0EWJ" /><figcaption>Raport Jest Code Coverage w postaci raportu HTML</figcaption></figure><p>Następny przykład jako raport zmiany pokrycia w sekcji Merge Request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*u9hz7DTI_dnnAjlg.png" /><figcaption>Zmiana (-2.45%) procentowego pokrycia kodu w Merge Request. Gitlab</figcaption></figure><h4>Testy statyczne (standard kod.)</h4><p>Test polega na automatycznym sprawdzaniu kodu w celu znalezienia błędów. Przykładowe narzędzia tj. sonarqube, codeclimate, eslint itp.</p><p>Poniżej przykład testu analizy statycznej kodu źródłowego z użyciem eslint</p><pre>$ eslint . --fix<br>/Users/qunabu/Desktop/localhost/pupile-web/src/actions/UserActions.js<br>   33:26  error  &#39;res&#39; is defined but never used  no-unused-vars<br>  123:12  error  &#39;res&#39; is defined but never used  no-unused-vars<br>  139:12  error  &#39;res&#39; is defined but never used  no-unused-vars<br><br>/Users/qunabu/Desktop/localhost/pupile-web/src/components/ArticlesPage/ArticlesPage.js<br>  31:11  error  Missing &quot;key&quot; prop for element in iterator  react/jsx-key<br><br>/Users/qunabu/Desktop/localhost/pupile-web/src/reducers/Visits.js<br>  100:7  error  Unexpected lexical declaration in case block  no-case-declarations<br><br>/Users/qunabu/Desktop/localhost/pupile-web/src/utils/utils.js<br>  17:13  error  Do not access Object.prototype method &#39;hasOwnProperty&#39; from target object  no-prototype-builtins<br><br>✖ 92 problems (92 errors, 0 warnings)<br>...</pre><p>Oraz codeclimate</p><pre>~ codeclimate analyze<br>Starting analysis<br>Running structure: Done!<br>Running duplication: Done!<br>Running eslint: Done!<br><br>== coverage/lcov-report/block-navigation.js (2 issues) ==<br>2-78: Function `init` has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. [structure]<br>2-78: Function `init` has 57 lines of code (exceeds 25 allowed). Consider refactoring. [structure]<br><br>== coverage/lcov-report/sorter.js (3 issues) ==<br>2-168: Function `addSorting` has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring. [structure]<br>2-168: Function `addSorting` has 138 lines of code (exceeds 25 allowed). Consider refactoring. [structure]<br>126-157: Function `enableUI` has 26 lines of code (exceeds 25 allowed). Consider refactoring. [structure]<br><br>== src/actions/ArticleActions.js (1 issue) ==<br>19-29: Similar blocks of code found in 3 locations. Consider refactoring. [duplication]<br>...</pre><ul><li><strong>Wydajnościowe<br>- </strong>sprawdzimy obciążenie systemu. Jak długo trwa odpowiedź serwera itp.</li><li><strong>Przeciążeniowe (część wydajnościowych)<br>- </strong>przy ograniczeniu bądź braku zasób tj: procesor, pamięć, dysk, itp.</li><li><strong>Obciążeniowe</strong><br>- przy zwiększonej ilości użytkowników, rekordów, itp.</li><li><strong>Użyteczności (ux)<br>- </strong>łatwość korzystania z oprogramowania.</li><li><strong>Pielęgnowalności</strong><br>- łatwość modyfikacji i dostosowań do nowych wymagań.</li><li><strong>Niezawodności</strong><br>- wykonanie wymaganych funkcji w określonych warunkach.</li><li><strong>Przenaszalności</strong><br>- łatwość przeniesienia z jednego środowiska na drugie.</li></ul><h4>Testy integracyjne</h4><p>Testy integracyjne sprawdzają, czy różne moduły lub usługi wykorzystywane przez oprogramowanie dobrze ze sobą współpracują. Tego poziomu testy mogą być stosowane na przykład w celu sprawdzania interakcji aplikacji z bazą danych lub upewnienia się, że mikro-usługi działają zgodnie z postawionymi wymaganiami i oczekiwaniami, wymagają one uruchomienia wielu elementów aplikacji.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5b9b96f329941af05a90b4ee65621de3/href">https://medium.com/media/5b9b96f329941af05a90b4ee65621de3/href</a></iframe><h4>Testy end-to-end (e2e)</h4><p>Symulują zachowanie użytkownika korzystającego z oprogramowania w pełnym środowisku aplikacji, sprawdzają czy wszystkie elementy aplikacji działają zgodnie z założeniami.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/782834517ee855d6c79c305706e539ba/href">https://medium.com/media/782834517ee855d6c79c305706e539ba/href</a></iframe><h4>Testy akceptacyjne (BDD)</h4><p>Testy akceptacyjne są formalnymi testami oprogramowania przeprowadzanymi w celu sprawdzenia, czy dany system spełnia stawiane przed nim wymagania biznesowe. Wymagają one uruchomienia i poprawnego działania całości aplikacji i polegają na replikowaniu zachowań użytkowników. Tego poziomu testy mogą także obejmować nieco szerszy zakres, w który może wejść między innymi pomiar wydajności systemu oraz odrzucenie zmian w przypadku, gdy nie pozwalają one na osiągnięcie postawionych celów i wymagań.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eba4905bedb7bc566f2d941161fc5d5e/href">https://medium.com/media/eba4905bedb7bc566f2d941161fc5d5e/href</a></iframe><h4>Testy wizualne (snapshot)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FcwartuRkChTawiL" /><figcaption>Test porównujący zmianę kodu w kontekście wizualnym. Percy</figcaption></figure><p>Porównywanie wyniku uruchomienia funkcji z jakimś oczekiwanym efektem, zapisanego wcześniej w repozytorium jak wzorzec prawidłowego rezultatu.<br><strong>Testy snapshot kodu.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*__pcXiijDKqB6llq" /><figcaption>Jest Snapshot Test</figcaption></figure><h3>Środowiska uruchomieniowe</h3><p>aka <strong>Test Runners</strong> — środowiska w którym testy są uruchamiane i z którego API korzystają. Runnery zazwyczaj posiadają podobne API, np Jasimne, Jest i Mocha.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1a46d851249bd7a17baa89efd489de0f/href">https://medium.com/media/1a46d851249bd7a17baa89efd489de0f/href</a></iframe><h4>Przygotowanie</h4><p>Funkcjonalne testy wymagają przygotowania środowiska pod testy, np poprzez funkcję beforeEach, beforeAll, afterEach i afterAll.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/94ec6859b93b2570cb2c31537ab4f58a/href">https://medium.com/media/94ec6859b93b2570cb2c31537ab4f58a/href</a></iframe><h4>Mocks (Moki)</h4><p>Obiekty które udają inne serwisy, np. wysyłanie maili.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5e3843f7310407cda79fb4cd21ab9efe/href">https://medium.com/media/5e3843f7310407cda79fb4cd21ab9efe/href</a></iframe><p>Udawanie zewnętrznego REST API.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e3f3be72cc5573dd67527398c8752b0b/href">https://medium.com/media/e3f3be72cc5573dd67527398c8752b0b/href</a></iframe><h4>Faktorie (factories)</h4><p>Służą do łatwego generowania skomplikowanych obiektów.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8c7d595255ddb7c88d5c7ba4e6f5cf46/href">https://medium.com/media/8c7d595255ddb7c88d5c7ba4e6f5cf46/href</a></iframe><h3>Zasady</h3><p>Testy jednostkowa są wyizolowanie i niezależne od siebie.</p><ul><li>Każdą funkcjonalność należy określić w jednym i tylko jednym teście</li><li>Wykonanie / kolejność uruchomienia jednego testu nie może wpływać na inne</li><li>Kod ma być niezależny, gotowy do współbieżności (parallel computing)</li><li>Powtarzalny</li><li>Szybki</li><li>Zwarty i logiczny</li><li>Łatwy do pisania i czytania</li><li>Testy jednostkowe to także kod źródłowy (poziom jakości, co testowany kod)</li></ul><p>Kluczem do dobrego testu jednostkowego jest napisanie testowalnego kodu. Zastosowanie prostych zasad projektowania może pomóc w szczególności:</p><ul><li>Używaj dobrej konwencji nazewnictwa i komentuj swój kod („dlaczego?”, A nie „jak”) ale pamiętaj, że komentarze nie zastępują złego nazewnictwa lub złego projektu</li><li>DRY: nie powtarzaj się, unikaj powielania kodu. Używaj abstrakcji. Pisz tzn Helpery</li><li>Pojedyncza odpowiedzialność: każdy przedmiot / funkcja musi skupiać się na jednym zadaniu (<strong>S</strong>OLID)</li><li>Zachowaj jeden poziom abstrakcji w tym samym komponencie (na przykład nie mieszaj logiki biznesowej ze szczegółami technicznymi niższego poziomu w tej samej metodzie)</li><li>Minimalizuj zależności między komponentami: hermetyzuj, wymieniaj mniej informacji między komponentami</li><li>Konfigurowalność zamiast hard-coding, metaprogramowanie - co zapobiega konieczności replikowania dokładnie tego samego środowiska podczas testowania</li><li>Zastosuj odpowiednie wzorce projektowe, zwłaszcza wstrzyknięcie zależności (dependency injection), które pozwala oddzielić odpowiedzialność za tworzenie obiektu od logiki biznesowej.</li><li>Unikaj globalnego stanu zmiennego</li></ul><p>Powyższe zasady nie odnoszą się tylko do testowania ale ogólnie do profesjonalnego programowania — powyższe porady nierzadko zaczerpnięte są z takich definicji jak <em>programowanie funkcyjne</em> , <em>KISS</em>, <em>DRY</em> lub <em>SOLID</em>.</p><h4><strong><em>Test Driven Development</em></strong>. Tam gdzie to możliwe używaj TDD</h4><p><strong><em>Test Driven Development</em></strong> to proces projektowania, a nie proces testowania. TDD to solidna metoda interaktywnego projektowania komponentów oprogramowania („jednostek”), tak aby ich zachowanie było określane za pomocą testów jednostkowych.</p><p><strong>Pierwszy cykl testowy</strong></p><ol><li>Napisz prosty test zakończony niepowodzeniem</li><li>Niech test przejdzie, wpisując minimalną ilość kodu, nie przejmuj się jakością kodu</li><li>Refaktoryzuj kod, stosując zasady / wzorce projektowe</li></ol><p><strong>Konsekwencje pierwszego cyklu testowego</strong></p><ul><li>Napisanie testu najpierw sprawia, że projekt kodu jest de facto testowalny</li><li>Pisanie tylko takiej ilości kodu potrzebnego do zaimplementowania wymaganej funkcjonalności sprawia, że wynikowa baza kodu jest minimalna, a tym samym łatwiejsza w utrzymaniu</li><li>Bazę kodu można rozbudować za pomocą mechanizmów refaktoryzacji, testy dają pewność, że nowy kod nie modyfikuje istniejących funkcjonalności</li><li>Czyszczenie kodu w każdym cyklu sprawia, że baza kodu jest łatwiejsza w utrzymaniu, znacznie tańsza jest częsta zmiana kodu w małych przyrostach</li><li>Szybka informacja zwrotna dla programistów, wiesz, że nic nie psujesz i że ewoluujesz system w dobrym kierunku</li><li>Zapewnia pewność dodawania funkcji, naprawiania błędów lub odkrywania nowych projektów</li><li>Kod napisany bez podejścia test-first jest często bardzo trudny do przetestowania.</li></ul><h3>Dobre praktyki pisania testów</h3><h4>Strukturyzuj/grupuj testy</h4><p>nie ustrukturyzowany kod ☹️</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/847d218a5c34ef6f58092f1a555e6217/href">https://medium.com/media/847d218a5c34ef6f58092f1a555e6217/href</a></iframe><p>lepiej 😁</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/25139bcf63f6bba6da126b12a544705d/href">https://medium.com/media/25139bcf63f6bba6da126b12a544705d/href</a></iframe><h4>Nazewnictwo</h4><p>Nazwij swoje testy poprawnie — zwięzłe, jednoznacznie, opisowo i poprawnie w języku angielskim. Przeczytaj dane wyjściowe programu uruchamiającego specyfikację i sprawdź, czy jest zrozumiałe! Pamiętaj, że ktoś inny też to przeczyta. Testy mają być żywą dokumentacją kodu.</p><p>nic nie mówiące nazwy ☹️</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1ba83fa5d8f30924b943626cd047db6a/href">https://medium.com/media/1ba83fa5d8f30924b943626cd047db6a/href</a></iframe><p>bardziej opisujące przypadek nazewnictwo 😁</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/80101282eb95cbc567c404e5d52b2ed0/href">https://medium.com/media/80101282eb95cbc567c404e5d52b2ed0/href</a></iframe><p>Dobra praktyka w nazywaniu testów 😁</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1633b82f9be0319ec6f7ac70cc5b6e6a/href">https://medium.com/media/1633b82f9be0319ec6f7ac70cc5b6e6a/href</a></iframe><h4>Unikaj logiki</h4><p>Zawsze używaj prostych instrukcji (expressions). Nie używaj pętli i / lub warunków. Jeśli to zrobisz, dodajesz możliwy punkt wejścia dla błędów w samym teście:</p><ul><li>Warunki (Conditions): nie wiesz, jaką ścieżką przejdzie test (źle)</li><li>Pętle (Loops): możesz udostępniać stan między testami (źle)</li></ul><p>brzydko-stosowanie logiki w teście☹️</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cd0cb62072d2249a943285d6e80f0a63/href">https://medium.com/media/cd0cb62072d2249a943285d6e80f0a63/href</a></iframe><p>w momencie w który powyższy test zwróci błąd dostaniesz informację, że błąd wystąpił w linii 12, ale już odszukanie który konkretnie był to przypadek będzie trudne. O wiele lepiej jest napisać tak 😁</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/99ca8e18391f18fce7f0d1903722ffba/href">https://medium.com/media/99ca8e18391f18fce7f0d1903722ffba/href</a></iframe><p><strong>Najlepiej</strong>: test dla każdego przypadku. Zapewni ładny raport wszystkich możliwych przypadków, poprawiając łatwość konserwacji. 😁😁😁</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7ae55e2aff331d59fb2738884fb122fe/href">https://medium.com/media/7ae55e2aff331d59fb2738884fb122fe/href</a></iframe><h4>Nie pisz zbędnych oczekiwań (expect)</h4><p>Pamiętaj, testy jednostkowe to specyfikacja projektu określająca, jak powinno działać określone zachowanie, a nie lista obserwacji wszystkiego, co dzieje się w kodzie.</p><p>Ten kod sprawdza implementację a nie działanie ☹️</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f150f998ab0f062c4d3aa6ad8ec0db75/href">https://medium.com/media/f150f998ab0f062c4d3aa6ad8ec0db75/href</a></iframe><p>o wiele lepiej jest 😁</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/54f3c48767a52cfc4877bfdf7c6927fa/href">https://medium.com/media/54f3c48767a52cfc4877bfdf7c6927fa/href</a></iframe><p>Poprawi to łatwość konserwacji ( maintainability). Twój test nie jest już powiązany ze szczegółami implementacji.</p><h4>Prawidłowo skonfiguruj działania, które mają zastosowanie do wszystkich testów</h4><p>Działania przygotowujące testy nie powinny być treścią samego testu.</p><p>brzydko ☹️</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b3ab35f14ff69d7f69feb0b3a54b5fc3/href">https://medium.com/media/b3ab35f14ff69d7f69feb0b3a54b5fc3/href</a></iframe><p>lepszy kod — testy skupiają się na swojej treści 😁</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ee2a7ddfc1c14477d0369809f38eb678/href">https://medium.com/media/ee2a7ddfc1c14477d0369809f38eb678/href</a></iframe><p>Zwróć uwagę gdzie powinien być wywołany jasmine.Ajax.install();</p><h4>Znaj na wylot testowy framework</h4><p>brzydko ☹️</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ad6dbd907749ab3a08c027016ac331b7/href">https://medium.com/media/ad6dbd907749ab3a08c027016ac331b7/href</a></iframe><p>o wiele lepiej jest korzystać z API runnera 😁</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/50e65a6fa4b4145f28407b56101ddbd4/href">https://medium.com/media/50e65a6fa4b4145f28407b56101ddbd4/href</a></iframe><h4>Nie sprawdzaj wielu problemów w tym samym teście</h4><p>Jeśli metoda ma kilka wyników końcowych, każdą z nich należy przetestować oddzielnie. W każdym przypadku, gdy pojawi się błąd, pomoże ci zlokalizować źródło problemu w dokładnym miejscu.</p><p>Pisanie „AND” lub „OR” podczas nazwania testu oznacza raczej refaktoryzację testu.</p><p>brzydko — test chce za dużo sprawdzać☹️</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5bb64221ecc2f9d8e9960093f7414c7b/href">https://medium.com/media/5bb64221ecc2f9d8e9960093f7414c7b/href</a></iframe><p>lepiej, rozdzielamy powyższe na osobne testy 😁</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5bb1d6dab1cadfca9af5ab46dacb7e91/href">https://medium.com/media/5bb1d6dab1cadfca9af5ab46dacb7e91/href</a></iframe><h4>Pokryj przypadek ogólny i wszystkie brzegowe</h4><p>Nieprzewidziane zachowanie zwykle zdarza się na krawędziach ( edge case) - Pamiętaj, że testy mają być żywą dokumentacją kodu. Przykład testowania <a href="https://pl.wikipedia.org/wiki/Odwrotna_notacja_polska">Odwrotnej Polskiej Notacji</a>.</p><p>ten test nie sprawdza wszystkiego ☹️</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/14e2661803fd70250aed02907aabfdbc/href">https://medium.com/media/14e2661803fd70250aed02907aabfdbc/href</a></iframe><p>ten test sprawdza o wiele więcej 😁 — przypadki brzegowe dla RPN</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f276d003fb7f4ce5fed442b5081536fc/href">https://medium.com/media/f276d003fb7f4ce5fed442b5081536fc/href</a></iframe><h4>Stosując TDD, zawsze zaczynaj od napisania najprostszego testu zakończonego niepowodzeniem</h4><p>Twój pierwszy test raczej nie powinien wyglądać tak ☹️</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f932589f144c03b3a45d9a91ccc46aa5/href">https://medium.com/media/f932589f144c03b3a45d9a91ccc46aa5/href</a></iframe><p>a raczej tak 😁</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e298a227f7d1d89e85d70bf32ccefd26/href">https://medium.com/media/e298a227f7d1d89e85d70bf32ccefd26/href</a></iframe><p>Od tego momentu zacznij stopniowo dodawać funkcjonalności, np taką z powyższego testu.</p><h4>Testuj zachowanie, a nie implementację</h4><p>brzydko ☹️ ponieważ implementacja może ulec zmianie w przyszłości</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2093d5e6e7111490f3ddd4b4a98c7cd7/href">https://medium.com/media/2093d5e6e7111490f3ddd4b4a98c7cd7/href</a></iframe><p>o wiele lepiej przy okazji testujesz API)😁</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/84644374bbf5f6f432533d03b84d2d13/href">https://medium.com/media/84644374bbf5f6f432533d03b84d2d13/href</a></iframe><h4>Twórz nowe testy dla każdej usterki</h4><p>Zawsze, gdy zostanie znaleziony błąd, przed poprawieniem kodu utwórz test, który powiela problem. Następnie zastosuj TDD, aby to naprawić.</p><h4>Nie pisz testów jednostkowych dla złożonych interakcji użytkownika</h4><p>Tym zajmują się testy funkcyjne.</p><p><strong>Przetestuj proste działania użytkownika</strong></p><p>Przykład prostych działań użytkownika:</p><ul><li>Kliknięcie linku, który przełącza widoczność elementu DOM</li><li>Przesłanie formularza, który uruchamia walidację formularza</li></ul><h4>Najpierw czytaj kod testowy</h4><p>Przeglądając (nowy) kod, zawsze zaczynaj od przeczytania kodu testów. Testy to małe przypadki użycia kodu, do których można przejść.</p><p>Pomoże ci to bardzo szybko zrozumieć zamiary dewelopera (wystarczy spojrzeć na nazwy testów) oraz uzupełnia to dokumentację techniczną projektu — w niektórych przypadkach jest to jedyna dostępna dokumentacja.</p><h3>LiveCoding</h3><p><a href="https://www.linkedin.com/feed/hashtag/?keywords=livecoding&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A6737475007003324416">#LiveCoding</a>: testowanie prostej aplikacji napisanej w <a href="https://www.linkedin.com/feed/hashtag/?keywords=react&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A6737475007003324416">#React</a> z <a href="https://www.linkedin.com/feed/hashtag/?keywords=create&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A6737475007003324416">#create</a>-react-app.</p><ul><li><strong>LiveCoding</strong> jako nagrany screencast dostępny jest na YouTube — <a href="https://www.youtube.com/watch?v=tjo_oJm6pJU">https://www.youtube.com/watch?v=tjo_oJm6pJU</a></li><li>Kod na którym oparte jest coding dostępny jest w repozytorium <a href="https://github.com/qunabu/js-testing-types">https://github.com/qunabu/js-testing-types</a></li></ul><p>Kod w tym repozytorium jest oparty o React i domyślne ustawienia create-react-app, oprócz tego zawiera:</p><ul><li>Prostą aplikację do której podłączone są testy.</li><li>Runner do testów Jest. Testy jednostkowe i integracyjne w plikach **/*.test.js</li><li>Framework do testowania komponentów Reacta <a href="https://github.com/testing-library/react-testing-library">react-testing-library</a></li><li>Runner do testów end-to-end (e2e) <a href="https://www.cypress.io/">cypress</a>. Definicje testów w katalogu <a href="https://github.com/qunabu/js-testing-types/blob/master/cypress">cypress</a></li><li><a href="https://github.com/typicode/husky">Pre hook git-push</a> uruchamiający testy w momecie git push. Kod który nie przechodzi testów Jest nie będzie wysłany do repozytorium.</li><li>Skonfigurowany Continuous Integration oparty o CircleCi</li><li>Runner do testów akceptacyjnych i BDD (Behaviour Driven Development) <a href="https://codecept.io/">https://codecept.io/</a></li></ul><p>Korzystałem z otwartych materiałów, tj</p><ul><li><a href="https://github.com/mawrkus/js-unit-testing-guide">A guide to unit testing in JavaScript. Marc Mignonsin</a></li><li><a href="https://jestjs.io/">Jest is a delightful JavaScript Testing Framework</a></li><li><a href="https://github.com/facebook/create-react-app">create-react-app</a></li><li><a href="https://www.cypress.io/">Cypress Test Runner</a></li><li><a href="https://codecept.io/">CodeceptJS — SuperCharged End 2 End Testing with WebDriver &amp; Puppeteer</a></li></ul><p>Mateusz Wojczal 2020<br><a href="https://mateusz.wojczal.com/">https://mateusz.wojczal.com</a></p><p><em>Originally published at </em><a href="https://github.com/qunabu/js-testing-types/tree/master/slides"><em>https://github.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=81193dd023b9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Strapi testing. more examples]]></title>
            <link>https://medium.com/qunabu-interactive/strapi-testing-more-examples-b09b07088353?source=rss-684cabb8f247------2</link>
            <guid isPermaLink="false">https://medium.com/p/b09b07088353</guid>
            <category><![CDATA[circleci]]></category>
            <category><![CDATA[strapi]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[jest]]></category>
            <dc:creator><![CDATA[Mateusz Wojczal]]></dc:creator>
            <pubDate>Thu, 15 Oct 2020 19:14:30 GMT</pubDate>
            <atom:updated>2020-10-19T08:27:17.671Z</atom:updated>
            <content:encoded><![CDATA[<h3>Strapi testing with Jest. More examples #1.</h3><p>In this article I’ll try to focus on pure examples of testing strategies in Strapi 3. It’s a continuation of previous <a href="https://medium.com/qunabu-interactive/strapi-jest-testing-with-gitlab-ci-82ffe4c5715a">medium post</a></p><p>All the examples are covered in <a href="https://github.com/qunabu/strapi-unit-test-example">github repository</a> and all the tests are run by <a href="https://circleci.com/gh/qunabu/strapi-unit-test-example">CircleCi</a>.</p><h3>Supporting tools</h3><p>For a more efficient (DRY) workflow I’m going to use the same straight-forward factories for mock objects and helpers to interact with strapi instance.</p><h4>Factories</h4><p><strong>User factory</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/636ea334c95a950b51d1ab62261e2d21/href">https://medium.com/media/636ea334c95a950b51d1ab62261e2d21/href</a></iframe><h4><strong>Extended helpers</strong></h4><p>Strapi general helper was introduced in a previous article, yet this one is a bit extended.</p><p><strong>Strapi helper</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/080032ef8dcfeaff362740402928f3d3/href">https://medium.com/media/080032ef8dcfeaff362740402928f3d3/href</a></iframe><h4>JSON Web Token signed request</h4><p>To get a Bearer token required for all authenticated requests you can either</p><p>- call /auth/local endpoint or<br>- use strapi.plugins[“users-permissions”].services.jwt.issue method.</p><p>Strapi helper from above contains method jwt to perform fetching the token</p><h3>Allowing roles for test routes</h3><p>A custom route and controller that is not public (needs JWT token in Request header) must be assigned to role — otherwise even for a valid token controller will throw Forbidden 403 error. The whole process is described in <a href="https://strapi.io/documentation/v3.x/guides/auth-request.html#setup">Authenticated request</a> tutorial on Strapi documentation page. This information is saved in the database only.</p><p>During a tests we need to be able to mimic the administrator panel. Helper grantPrivilage allows that.</p><h4>Example</h4><p>Lets create an endpoint that for an authenticated user returns a text Hi ${ctx.state.user.username}.</p><p>./api/hello/config/routes.json</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/28eda8bafd898d0c4feb15436528c1e5/href">https://medium.com/media/28eda8bafd898d0c4feb15436528c1e5/href</a></iframe><p>./api/hello/controllers/Hello.js</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/07e8e31fdf1f1767bb3e18bee0410a27/href">https://medium.com/media/07e8e31fdf1f1767bb3e18bee0410a27/href</a></iframe><p>Yet the test</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/423905b8675626ccef680b763ddbd6f8/href">https://medium.com/media/423905b8675626ccef680b763ddbd6f8/href</a></iframe><p>will not work, because /hi is not assigned to a role that user is. The following code fix this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9c78c7873c75985c9428623d3f61268f/href">https://medium.com/media/9c78c7873c75985c9428623d3f61268f/href</a></iframe><h3>Testing sending emails</h3><p>For testing if emails are sent and their content one need to <a href="https://strapi.io/documentation/v3.x/plugins/email.html#create-new-provider">create new provider</a>— <em>a mock one</em>.</p><p>nodemailer-mock allows us to mock the nodemailer and test what we need. Add module to dependencies with <br>yarn add nodemailer-mock and create a new config for test environment.</p><p>./config/env/test/plugins.js</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a4e6ab37f40044bdf0a63de57ae03d4c/href">https://medium.com/media/a4e6ab37f40044bdf0a63de57ae03d4c/href</a></iframe><h3>Examples (test files)</h3><p>Below are first part of examples.</p><h4>Custom endpoint</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ba4f328f5c406870b7ea055c1e8b1b0a/href">https://medium.com/media/ba4f328f5c406870b7ea055c1e8b1b0a/href</a></iframe><h4>User tests</h4><p>If the following file test checks if</p><ul><li>user can register</li><li>user can login (jwt tokens are fine)</li><li>user can confirm his account with received email with confirmation link</li><li>user can’t login if account is not confirmed</li></ul><p>performs sample e2e test, in the following sequence:</p><ol><li>Sends a request to register new user</li><li>Tests if user exists in database now and it is not confirmed</li><li>User should not be able to login at this stage</li><li>Email is being sent</li><li>Fetch and test confirmation link from email content</li><li>Calling a email-confirmation should confirm user and return a 302 redirect</li><li>Check in database if user in confirmed now, link from email was clicked</li><li>Finally user can login in</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a0b29aa6f3c61578a55be00371bdec2f/href">https://medium.com/media/a0b29aa6f3c61578a55be00371bdec2f/href</a></iframe><p>Next file test if</p><p>- user can reset password with received email with reset link</p><ol><li>Send email to forgot password</li><li>The code with new password on /auth/reset-password</li><li>Change password</li><li>Test if password has changed</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9663bc1c5411a572cf73b529427c4f6c/href">https://medium.com/media/9663bc1c5411a572cf73b529427c4f6c/href</a></iframe><p>This series of articles are going to be continued, so please stay tuned.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b09b07088353" width="1" height="1" alt=""><hr><p><a href="https://medium.com/qunabu-interactive/strapi-testing-more-examples-b09b07088353">Strapi testing. more examples</a> was originally published in <a href="https://medium.com/qunabu-interactive">Escolasoft</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Strapi Jest Testing with Gitlab CI.]]></title>
            <link>https://medium.com/qunabu-interactive/strapi-jest-testing-with-gitlab-ci-82ffe4c5715a?source=rss-684cabb8f247------2</link>
            <guid isPermaLink="false">https://medium.com/p/82ffe4c5715a</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[strapi]]></category>
            <category><![CDATA[jest]]></category>
            <category><![CDATA[gitlab]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <dc:creator><![CDATA[Mateusz Wojczal]]></dc:creator>
            <pubDate>Sun, 19 Apr 2020 19:06:49 GMT</pubDate>
            <atom:updated>2020-11-17T13:50:02.835Z</atom:updated>
            <content:encoded><![CDATA[<p><strong><em>Edit</em></strong><em>. After publishing this article I was contacted by Strapi team which ended with this </em><a href="https://strapi.io/documentation/v3.x/guides/unit-testing.html#install-test-tools"><em>official tutorial as part of Strapi 3 documentation</em></a><em>. Thank you Strapi team for that.<br></em><a href="https://medium.com/qunabu-interactive/strapi-testing-more-examples-b09b07088353"><em>More examples are covered in the next article</em></a><em>.</em></p><p>Recently I started working with amazing Strapi Headless CMS. After reading all the documentation I was quite shocked that there is not even one sentence about any kind of testing (unit, e2e, whatsoever) with that software. Also after reading comments in Github issues, Slack channel, Stack Overflow and similar resources I realised that this topic is very much neglected. This is really a shame and should be fix as soon as possible by Strapi team if they want this framework to be consider mature and professional.</p><p>Yet, I haven’t gave up on Strapi, still finding it as a great tool for rapid programming, one of the most promising in node.js world in terms of Headless CMSes. So I’ve decided to do a research on my own and write done straight forward tutorial on how to achieve easy testing. In this article I will cover topic of creating a simplest API endpoint — a heartbeat check and it’s unit test.</p><h3>Installing new Strapi instance and dependencies.</h3><p>I’m creating a new default settings Strapi instance by running command</p><pre>yarn create strapi-app my-project --quickstart</pre><p>which creates a default Strapi instance in my-project folder. Once this is done we need some additional npm packages, for jest testing purpose</p><pre>yarn add --dev jest jest-junit junit supertest</pre><ul><li>jest is our testing framework</li><li>junit is required by Gitlab CI to display each test in Merge Request view</li><li>supertest will be used to test our heartbeat endpoint</li></ul><p>Jest when called is switching NODE_ENV to test which requires additional Strapi environment configuration.</p><p>Copy contents of my-project/config/environments/production into my-project/config/environments/test and put some changes. Edit my-project/config/environments/test/database.json and add value &quot;filename&quot;: &quot;.tmp/test.db&quot; — reason of that is that we want to have a separate sqlite database for tests, so our test will not touch real data. The whole file will look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce7bf1f1526aa7089fe4c694f17da4af/href">https://medium.com/media/ce7bf1f1526aa7089fe4c694f17da4af/href</a></iframe><h3>Getting Strapi instance for tests.</h3><p>This part is one that people have most problem with, and it is the main reason this article is written.</p><p>I’ll create a folder tests where all the tests will be put and inside it, I’ll create another folder helpers where I’ll add main Strapi helper in file strapi.js. File my-project/tests/helpers/strapi.js contents is as follows.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/78a4d4af5728e62977753212568d5cbd/href">https://medium.com/media/78a4d4af5728e62977753212568d5cbd/href</a></iframe><p>This is all we need for writing a simple API endpoint unit test.</p><h3>Heartbeat endpoint</h3><p>Now let’s create a simple endpoint we’re going to test. Endpoint will serve simple purpose will expose /heartbeat GET request that will return Hello World . You can create this easily with Strapi CLI and the result will be as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/515fb265a0e9e2f35176cd5b4327ddfa/href">https://medium.com/media/515fb265a0e9e2f35176cd5b4327ddfa/href</a></iframe><p>You can launch the app with npm run start and under <a href="http://localhost:1337/heartbeat">http://localhost:1337/heartbeat</a> you should see “Hello World”. This is an endpoint we’re going to unit test.</p><h3>Jest unit endpoint test</h3><p>I’ll write as simple Jest unit test that will test if the /heartbeat GET request is returning Hello World. Here is a test. Descriptions are in the comments.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe6af478e08f2bb61cf8e8231bed248c/href">https://medium.com/media/fe6af478e08f2bb61cf8e8231bed248c/href</a></iframe><p>Have a look on beforeAll jest method where I call the helper mentioned in section above.</p><p>Thats the whole test, save it in file my-project/tests/app.test.js and run it with the command:</p><pre>./node_modules/.bin/jest --detectOpenHandles</pre><p>which should return an output similar to</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W7D6IcYCL_KDYbhW99nu7w.png" /><figcaption>Result of jest testing</figcaption></figure><p>and that’s it — you’ve just created a first unit test for Strapi.</p><h3>Appendix. Continuous Integration</h3><p>Those test are best used within the Continuous Integration environment. Here I’ll explain how to append this to Gitlab CI, yet it would be easy to implement into any CI framework.</p><p>First of all lets add our testing commands into package.json scripts sections:</p><pre>&quot;scripts&quot;: {<br>  &quot;develop&quot;: &quot;strapi develop&quot;,<br>  &quot;start&quot;: &quot;strapi start&quot;,<br>  &quot;build&quot;: &quot;strapi build&quot;,<br>  &quot;strapi&quot;: &quot;strapi&quot;,<br>  &quot;test&quot;: &quot;./node_modules/.bin/jest --detectOpenHandles&quot;,<br>  &quot;test-ci&quot;: &quot;./node_modules/.bin/jest --detectOpenHandles --forceExit --watchAll=false --reporters=&#39;jest-junit&#39;&quot;<br>}</pre><p>which will allows us to run client test with npm run test and run CI test with npm run test-ci , please note a custom jest reporter jest-junit.</p><blockquote>The <strong>JUnit</strong> testing framework has introduced a XML file <strong>format</strong> to report about the test suite execution. These XML files can be processed by programs like Jenkins to display results of the tests.</blockquote><p>My intention is that each push of code will launch a Gitlab runner, that calls all of the tests and displays result of the tests in Merge Request view:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jS-qVSanvTIx8OhAzk0lsg.png" /><figcaption>Results of tests in Gitlab Merge Request.</figcaption></figure><p>Only when all of the tests pass user can merge code. To achieve this you need to have Gitlab with working runner(s). Here is an example gitlab.yml configuration. You need to put this file in the main folder.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/509af6475086a453fc2ebc74ecf0b5ac/href">https://medium.com/media/509af6475086a453fc2ebc74ecf0b5ac/href</a></iframe><p>After that code is pushed each next push will trigger a pipeline that will</p><ul><li>Attach node:alpine docker with our files</li><li>Install dependencies npm install</li><li>Run test with npm run test-ci</li><li>Tests will generate junit.xml file</li><li>Junit file will be uploaded to gitlab and displayed as a test report</li><li>In case any test will fail, Merge Request report will give you exact details of which test failed and why</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kb_BgWRxfVUqsRf-y1ptEg.png" /><figcaption>Example of success pipeline</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JZTrccrHC9jUERfWYpBSHA.png" /><figcaption>Example of failure pipeline</figcaption></figure><h3>What’s next</h3><ul><li>Here is mine <a href="https://github.com/qunabu/strapi-unit-test-example">github repository</a> with some other straight forward example regarding more samples of unit testing in Strapi.</li><li>I’ve covered the simplest possible example, yet with more sophisticated cases you would need to write some more complex helpers. In my opinion this should be delivered as a part of Strapi out of the box.</li><li>Most components of Strapi are based on koa, web framework for node.js When there are no decent articles about testing for Strapi there are many on testing for koa — this is when you start if you want to write test for your controllers.</li><li>Code coverage is note covered in this article yet it is an essential part of Continuous Integration which is both supported by JUnit and Gitlab.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=82ffe4c5715a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/qunabu-interactive/strapi-jest-testing-with-gitlab-ci-82ffe4c5715a">Strapi Jest Testing with Gitlab CI.</a> was originally published in <a href="https://medium.com/qunabu-interactive">Escolasoft</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript Functional Google Translate API to translate JSON values.]]></title>
            <link>https://medium.com/qunabu-interactive/javascript-functional-google-translate-api-to-translate-json-values-8f8f310dab7f?source=rss-684cabb8f247------2</link>
            <guid isPermaLink="false">https://medium.com/p/8f8f310dab7f</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[json]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[google-translate]]></category>
            <dc:creator><![CDATA[Mateusz Wojczal]]></dc:creator>
            <pubDate>Thu, 16 Jan 2020 12:15:38 GMT</pubDate>
            <atom:updated>2020-01-16T12:15:38.801Z</atom:updated>
            <content:encoded><![CDATA[<p>Google Translate is a service that allows you to automate translation from one language into another. It does translate not single terms but whole sentences as well. You can use it though the dedicated website but it also exposes API that can be used in bespoke applications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GlbFQxxOuVSsJnm0a8mw-A.png" /><figcaption>Google Translate website service</figcaption></figure><p>In order to use to API you need to get the API access key which in case of this particular service is not as straight forward as in case of other Google APIs like Google Maps.</p><p>In this article I’ll try to cover two topics:</p><ol><li>Getting the Bearer token required to call the Google Translate API</li><li>Using Google Translate API in JavaScript <strong>functional programming paradigm</strong></li></ol><p><em>Please note that first part of the tutorial covers only Linux and MacOs. There are some differences on Windows like installing SDK or setting environment variables.</em></p><p>Before we can start coding we need to get the token that will be used with every API call in our code. The steps below are also described in <a href="https://cloud.google.com/translate/docs/basic/setup-basic">Quickstart</a> but I’ll try to explain this easier. Later I’ll explain how to write a simple Node.JS script that will take JSON file as input and write another JSON file as output, so example file with polish terms like in the following snippet</p><pre>{<br> &quot;username&quot;: &quot;Login&quot;,<br> &quot;password&quot;: &quot;Hasło&quot;,<br> &quot;fullname&quot;: &quot;Imię i Nazwisko&quot;<br>}</pre><p>might be translated into german</p><pre>{<br> &quot;username&quot;: &quot;Einloggen&quot;,<br> &quot;password&quot;: &quot;Kennwort&quot;,<br> &quot;fullname&quot;: &quot;Vor- und Nachname&quot;<br>}</pre><h4>Getting the Service Key</h4><ol><li>Login or create an account in Google Developer Console</li><li>Create or select a project.</li><li>Enable the Cloud Translation API for that project.</li><li>Create a service account.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DoH2AAuUfR8tBvhsJ54YBQ.png" /></figure><p>5. Download a private key as JSON.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u1V595TMBT8gd6uSFh5qqQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/486/1*0dDF--_XwCbMm0obs4R5_Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bx7rvXWBQq4osDSiSLX4LQ.png" /></figure><p>6. Once you save that on you disk copy to clipboard the absolute path to it. In my case this file path is/Users/qunabu/Downloads/project-ad1f87bcae9e.json</p><p><strong>Install Google SDK</strong></p><ol><li>Download <a href="https://cloud.google.com/sdk/docs/">https://cloud.google.com/sdk/docs/</a> and follow the instruction on Google SDK download page.</li><li>Run the installation script ./google-cloud-sdk/install.sh from the folder where SDK was extracted.</li><li>After installation restart the shell and run command gcloud auth application-default print-access-token that should fail at this stage and ask for GOOGLE_APPLICATION_CREDENTIALS which is suppose to be path to key generated in the previous stage.</li><li>Set the path to key by setting environmental variable with export GOOGLE_APPLICATION_CREDENTIALS=/Users/qunabu/Downloads/project-ad1f87bcae9e.json</li><li>At this stage gcloud auth application-default print-access-token should return that Token that is needed to the application. Please note that this token is valid only for a limited short period of time.</li></ol><h4>Writing the translation script.</h4><p>Our application will be based <strong>functional programming paradigm</strong> in JavaScript language which is a huge topic. In this article I’m going to focus on</p><ul><li><strong>Pure functions</strong> which return value is only determined by its input values, without observable side effects and the always return the same results on particular input</li><li>No need to global variables and <strong>Immutability. </strong>We don’t change values we create new ones. Variables are passed as function arguments.</li><li><strong>Chaining </strong>which is a technique used to simplify code where multiple methods are applied to an object one after another.</li></ul><p>My code is going to perform single task — convert one object of language terms into translated ones.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LHy7_ki1saYKvyiX_m2gng.png" /><figcaption>Automated translation from polish to german.</figcaption></figure><p>Our first function is going to connect to Translation API and with support of <a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch">fetch</a> and <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a> resolve translated term or reject if fails.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7a5ccca6fc91d5516c8bb4c2584fecff/href">https://medium.com/media/7a5ccca6fc91d5516c8bb4c2584fecff/href</a></iframe><pre>// GKEY is key generated  `gcloud auth application-default print-access-token`</pre><pre>getTranslation({fullName:&quot;Full Name&quot;}, &#39;de&#39;, GKEY)<br>  .then(response =&gt; console.log(response)) // returns {fullName:&quot;Vollständiger Name&quot;}<br>  .catch(err =&gt; console.log(err)) // called in case of any error </pre><p><strong><em>Is this function pure?</em></strong> Actually it’s not because it does connect to API and side effect occurs — for instance with the same arguments like getTranslation({fullName:”Full Name”}, ‘de’, GKEY) can return different results because GKEY lifespan is short and is valid only for couple of minutes so the results is not always the same. Functions that depends on the environment is not pure but it’s nature — for instance API calls depends on the network connection</p><p>Please note the setTimeout exists in function because there is limited amount of simultaneous calls to API, so the function is calling it each 50 milliseconds.</p><p>Once we have function that actually translates the terms let’s create one that takes the key-value dictionary object and row by row translate them by calling getTranslation. Before that I would like to introduce two helpers functions that are going to be used.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/08b03aafd4f12a5be354c2f390d1ba6b/href">https://medium.com/media/08b03aafd4f12a5be354c2f390d1ba6b/href</a></iframe><p>Are convertToArray and convertToObject pure functions? Both of them do not mutate input data, have no side effect and for given inputs they always return the same results. Yes, they are pure, and they are based on Array methods <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map">map</a> and <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce">reduce</a> which are pure as well.</p><p>Now the function that process whole object row by row is below</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8760d641f196e0c8fb7ebc4276a652bc/href">https://medium.com/media/8760d641f196e0c8fb7ebc4276a652bc/href</a></iframe><p>Because it is related to getTranslation is not pure. Please note the recurrency which is one of the techniques often used in functional programming.</p><p>To see the final application code we need to include one more function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b2c208d221faf78c91721a3d4ace2b1a/href">https://medium.com/media/b2c208d221faf78c91721a3d4ace2b1a/href</a></iframe><p>which just loads an JSON file from local drive.</p><p>The final code of the app is below. It does use <strong>chaining</strong> technique from functional programming as well as method of catching errors <strong>without using throw/catch. </strong>convertToArray and convertToObject are not essential but its much easier to operate on the array cell by cell then on the pure object itself. The algorithm is straight forward:</p><ul><li>load and parse JSON from local files</li><li>convert object to array</li><li>process whole array row by row and return new array with translated terms</li><li>convert array to object</li><li>save object to new JSON file</li><li>in case of any of above steps fails, stop and show an error</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/be80bc043676ffbe31b2d51e16c1dcd4/href">https://medium.com/media/be80bc043676ffbe31b2d51e16c1dcd4/href</a></iframe><p>If you would like to play with the code the whole application is available on <a href="https://github.com/qunabu/translate-script">github</a>.</p><p>Example of translating terms from polish to english with the script:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*al9iQnX_9FBJheb2XBz_tQ.png" /><figcaption>Example of running the app in the console.</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8f8f310dab7f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/qunabu-interactive/javascript-functional-google-translate-api-to-translate-json-values-8f8f310dab7f">JavaScript Functional Google Translate API to translate JSON values.</a> was originally published in <a href="https://medium.com/qunabu-interactive">Escolasoft</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Node.js dummy email queue, when SMTP fails.]]></title>
            <link>https://medium.com/qunabu-interactive/node-js-dummy-email-queue-when-smtp-fails-70b8195c57ef?source=rss-684cabb8f247------2</link>
            <guid isPermaLink="false">https://medium.com/p/70b8195c57ef</guid>
            <category><![CDATA[meteor]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Mateusz Wojczal]]></dc:creator>
            <pubDate>Thu, 24 Jan 2019 10:12:59 GMT</pubDate>
            <atom:updated>2019-01-24T10:12:59.241Z</atom:updated>
            <content:encoded><![CDATA[<p>There are many npm packages that solves the following issue.</p><pre>                           |--------|<br>                     /--X--| SMTP 1 |<br>                    /   ^  |--------|<br>                   /    \--- Retry with next provider<br>|----------------|/        |--------|         |------------------|<br>|   Mail         | ---X--&gt; | SMTP 2 |      /-&gt;|  ^_^ Happy user  |<br>|----------------|\   ^    |--------|     /   |------------------|<br>                   \  \--- Retry         /<br>                    \      |--------|   /<br>                     \----&gt;| SMTP 3 |--/<br>                           |--------|</pre><p>The following diagram is taken from <a href="https://github.com/VeliovGroup/Meteor-Mailer/">Meteor-Mailer</a> which is based on <a href="https://github.com/nodemailer/nodemailer">nodemailer</a> which im going to use in the example below.</p><p>Code below is responsible for the following <br>1. Try to send email with default email (here it would be Meteor.JS email system) <br>2. If it fails, it starts email queue <br>3. It tries to send email with first email provider. If this fails it tries again with another. <br>4. If all fails, error callback is called.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/261121a3819ee5127cf9194db03ea742/href">https://medium.com/media/261121a3819ee5127cf9194db03ea742/href</a></iframe><p>Not that this script is dummy, in real scenarios real queue should be used, for instance one that is saved in Mongo.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=70b8195c57ef" width="1" height="1" alt=""><hr><p><a href="https://medium.com/qunabu-interactive/node-js-dummy-email-queue-when-smtp-fails-70b8195c57ef">Node.js dummy email queue, when SMTP fails.</a> was originally published in <a href="https://medium.com/qunabu-interactive">Escolasoft</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Quick tip. How to change Laravel user password from command line.]]></title>
            <link>https://medium.com/qunabu-interactive/quick-tip-how-to-change-laravel-user-password-from-command-line-515f55c9d295?source=rss-684cabb8f247------2</link>
            <guid isPermaLink="false">https://medium.com/p/515f55c9d295</guid>
            <category><![CDATA[laravel]]></category>
            <dc:creator><![CDATA[Mateusz Wojczal]]></dc:creator>
            <pubDate>Tue, 23 Oct 2018 13:02:12 GMT</pubDate>
            <atom:updated>2018-10-23T13:02:12.372Z</atom:updated>
            <content:encoded><![CDATA[<p>When you search google on how to change / reset user password most tips includes changing this from the database. Yet there is imho better way that use Laravels Tinker</p><blockquote>Laravel REPL</blockquote><blockquote>All Laravel applications include Tinker, a REPL powered by the <a href="https://github.com/bobthecow/psysh">PsySH</a> package. Tinker allows you to interact with your entire Laravel application on the command line, including the Eloquent ORM, jobs, events, and more. To enter the Tinker environment, run the tinker Artisan command:</blockquote><h4>Chaning password (or any other Model data)</h4><p>Launch the console from main folder with</p><p>php artisan tinker</p><p>After that you enters Laravels console — all commands from now are interpreted as php code. So to change user@example.com password you would just run.</p><pre>$user = App\User::where(&#39;email&#39;, &#39;user@example.com&#39;)-&gt;first();<br>$user-&gt;password = Hash::make(&#39;password&#39;);<br>$user-&gt;save();</pre><p>That’s it. Password changed.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=515f55c9d295" width="1" height="1" alt=""><hr><p><a href="https://medium.com/qunabu-interactive/quick-tip-how-to-change-laravel-user-password-from-command-line-515f55c9d295">Quick tip. How to change Laravel user password from command line.</a> was originally published in <a href="https://medium.com/qunabu-interactive">Escolasoft</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Drupal 8. Docker, composer, bootstrap, laravel-mix boilerplate. CI on GitLab]]></title>
            <link>https://medium.com/qunabu-interactive/drupal-8-docker-composer-bootstrap-laravel-mix-boilerplate-ci-on-gitlab-754b1ccdf3ec?source=rss-684cabb8f247------2</link>
            <guid isPermaLink="false">https://medium.com/p/754b1ccdf3ec</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[gitlab]]></category>
            <category><![CDATA[drupal]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Mateusz Wojczal]]></dc:creator>
            <pubDate>Tue, 23 Oct 2018 10:25:31 GMT</pubDate>
            <atom:updated>2018-10-23T10:32:27.532Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve created a simple boilerplate to rapidly develop Drupal application based on the technological stack we work day-to-day. Purpose of that was to implement new programmers in Drupal 8 environment in easy way.</p><p>The whole stack contains</p><ul><li>Drupal 8 installed from composer based on <a href="https://github.com/drupal-composer/drupal-project">https://github.com/drupal-composer/drupal-project</a></li><li>Drupal docker based on <a href="https://github.com/wodby/docker4drupal">https://github.com/wodby/docker4drupal</a></li><li>Bootstrap 4 theme and custom subtheme <a href="https://www.drupal.org/project/bootstrap_barrio">https://www.drupal.org/project/bootstrap_barrio</a></li><li>Laravel-mix that compiles scss and es6 javascript with npm scripts</li><li>Browsersync to refresh css and javascript changes at once without need of refreshing the window.</li></ul><h3>Installation. Step by step</h3><p>Start by creating new Drupal 8 instance from composer by calling</p><pre>composer create-project drupal-composer/drupal-project:8.x-dev helloworld --stability dev --no-interaction</pre><p>where helloworld is name of folder where the website will be stored.</p><p>Then we would merge this with a docker environment by cloning from docker4drupal and then copy the content of the drupal_docker_server into the helloworld folder</p><pre>git clone git@github.com:wodby/docker4drupal.git drupal_docker_server<br>rm -R drupal_docker_server/.git<br>cp -R drupal_docker_server helloworld</pre><p>Lets amend the volumes sections in drupal_docker_server/docker-compose.yml into</p><pre>  volumes:<br>    - ./../:/var/www/html</pre><p>and setup localhost by changing traefik.frontend.rule</p><pre>- &#39;traefik.frontend.rule=Host:localhost&#39;</pre><p>Now docker is ready to by launch</p><pre>cd helloworld<br>docker-compose up -d</pre><p>Visit <a href="http://localhost:8888/">http://localhost:8888/</a> to continue installation process. For database use the following settings</p><pre>DB_HOST: mariadb<br>DB_USER: drupal<br>DB_PASSWORD: drupal<br>DB_NAME: drupal<br>DB_DRIVER: mysql</pre><p>Drupal is installed now lets continue with setting up the frontend environment.</p><h3>Docker composer and drush.</h3><p>To call composer just run docker-compose exec php composer … and to run drush just call docker-compose exec php drush … for instance</p><pre>docker-compose exec php composer update</pre><p>or</p><pre>docker-compose exec php drush config-export</pre><h3>Bootstrap 4 sub-theme.</h3><p>Lets install bootstrap 4 Drupal theme</p><pre>docker-compose exec php composer require drupal/bootstrap_barrio</pre><p>now you need to copy files from subtheme folder into new custom theme. This way you would have sub-theme that extends main theme.</p><pre>cp -R web/themes/contrib/bootstrap_barrio/subtheme web/themes/custom/helloworld </pre><p>where helloworldis custom name of your theme</p><p>Rename the following files from bootstrap_barrio_subtheme to helloworld:<br>bootstrap_barrio_subtheme.theme to helloworld.theme<br>bootstrap_barrio_subtheme.info.yml to helloworld.info.yml<br>bootstrap_barrio_subtheme.libraries.ymlto helloworld.libraries.yml<br>/config/install/bootstrap_barrio_subtheme.settingsto /config/install/helloworld.settings<br>/config/schema/bootstrap_barrio_subtheme.schemato /config/schema/helloworld.schema</p><p>Edit the file helloworld.info.yml</p><pre>name: YourName<br>type: theme<br>description: &#39;Your Description.&#39;<br>version: VERSION<br>core: 8.x<br>base theme: bootstrap_barrio<br>libraries:<br>- helloworld/global-styling</pre><p>Delete the following:</p><pre># Information added by Drupal.org packaging script on 2015-11-29<br># version: &#39;8.x-4.0-beta1&#39;<br># core: &#39;8.x&#39;<br># project: &#39;bootstrap_barrio&#39;<br># datestamp: 1448759945<br></pre><pre># Information added by Drupal.org packaging script on 2018-04-30<br># version: &#39;8.x-4.9&#39;<br># core: &#39;8.x&#39;<br># project: &#39;bootstrap_barrio&#39;<br># datestamp: 1525127885<br></pre><pre># Information added by Drupal.org packaging script on 2018-05-27<br>version: &#39;8.x-4.12&#39;<br>core: &#39;8.x&#39;<br>project: &#39;bootstrap_barrio&#39;<br>datestamp: 1527445384</pre><p>Edit<strong> </strong>/config/schema/helloworld.schema.yml</p><pre># Schema for the configuration files of the Bootstrap Barrio Subtheme.</pre><pre>helloworld.settings:<br>type: theme_settings<br>label: &#39;YourTheme settings&#39;</pre><p>Edit /color/color.inc line 117</p><pre>// Preview files.<br>&#39;preview_library&#39; =&gt; &#39;helloworld/color.preview&#39;,<br>&#39;preview_html&#39; =&gt; &#39;color/preview.html&#39;,</pre><p>Edit<strong> </strong>helloworld<strong>.</strong>theme</p><p>Rename the function from:</p><pre>function bootstrap_barrio_subtheme_form_system_theme_settings_alter($form, FormStateInterface $form_state)</pre><p>to:</p><pre>function helloworld_form_system_theme_settings_alter($form, FormStateInterface $form_state)</pre><p>visit <a href="http://localhost:8888/">http://localhost:8888</a> login into admin panel, and enable the new theme.</p><h3>Laravel-mix boilerplate</h3><p>Once empty bootstrap sub-theme is installed lets establish scss and es6 deployment. We’re going to use superb laravel-mix package</p><blockquote><a href="https://github.com/JeffreyWay/laravel-mix">Laravel Mix</a> provides a fluent API for defining Webpack build steps for your Laravel application using several common CSS and JavaScript pre-processors. Through simple method chaining, you can fluently define your asset pipeline. For example:</blockquote><blockquote>mix<br> .js(&#39;resources/js/app.js&#39;, &#39;public/js&#39;)<br> .sass(&#39;resources/sass/app.scss&#39;, &#39;public/css&#39;);</blockquote><blockquote>If you’ve ever been confused and overwhelmed about getting started with Webpack and asset compilation, you will love Laravel Mix. However, you are not required to use it while developing your application. Of course, you are free to use any asset pipeline tool you wish, or even none at all.</blockquote><p>To init the laravel-mix create new npm package and get the dependencies by calling</p><pre>npm init <br>npm i laravel-mix -s</pre><p>We need to establish webpack settings and deploy scripts. Lest create in main folder next to package.json new file webpack.mix.js and put there the following contents</p><pre>const THEMEDIR = &quot;./web/themes/custom/helloworld&quot;;<br>let mix = require(&#39;laravel-mix&#39;);</pre><pre>mix<br>.browserSync({<br>  proxy: &#39;localhost:8888&#39;,<br>  files: [<br>   `${THEMEDIR}/js/global.js`,<br>   `${THEMEDIR}/css/*`,<br>]<br>})<br>.sass(`${THEMEDIR}/scss/style.scss`, `${THEMEDIR}/css`)<br>.js(`${THEMEDIR}/js/es6/global.js`, `${THEMEDIR}/js`)<br>.options({<br>  processCssUrls: false<br>})<br>.sourceMaps();</pre><p>and in package.json amend scripts section</p><pre>&quot;scripts&quot;: {<br>  &quot;dev&quot;: &quot;NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js&quot;,<br>  &quot;watch&quot;: &quot;NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js&quot;,<br>  &quot;hot&quot;: &quot;NODE_ENV=development webpack-dev-server --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js&quot;,<br>  &quot;production&quot;: &quot;NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js&quot;<br>},</pre><p>and lets create web/themes/custom/helloworld/es6/global.js js file, which would be entry file for all out js scripts.</p><p>Once this is setup, calling scripts npm run watch launches browser sync at available port (most likely <a href="http://localhost:3000)">http://localhost:3000)</a> and watches all the css and js changes. It runs browsersync so all the css changes are replaced without refreshing and all the js changes would refresh the browser. You change change browsersync settings in the webpack.mix.js file.</p><p>Script npm run prod compress css &amp; js into production ready files.</p><h3>Continuous Integration</h3><blockquote><strong><em>Note</em></strong> that the following setup is good only for staging or test server, not for production use.</blockquote><p>We’re going to use CI based on Gitlab. Basically after you push a code to develop branch this builds stage server by doing the following</p><ul><li>pulls all the data from the git server, and merge files</li><li>update composer dependencies</li><li>clear drupal cache</li><li>import config from yaml files</li><li>deploy javascript and scss on the server by calling npm</li></ul><p>You would need</p><ol><li>install the drupal instance on the server — this differs on each machine</li><li>have composer and npm installed (or you could user composer.phar file like in example below)</li><li>have access to the server by <a href="https://docs.gitlab.com/ee/ci/ssh_keys/">ssh key and add this key into GitLab variables</a>. Ssh key is saved into $SSH_PRIVATE_KEY variable</li></ol><p>First lets create deploy script build.sh. This is just an example you would have to change the values on your machine.</p><pre>#!/bin/sh<br>cd /home/qunabu/webapps/helloworld <br>git fetch<br>git reset --hard HEAD<br>git checkout develop<br>git pull<br>php72 composer.phar update<br>php72 /home/qunabu/helloworld/vendor/drush/drush/drush cache-rebuild<br>php72 /home/qunabu/helloworld/vendor/drush/drush/drush config-import --yes<br>npm i<br>npm run dev<br>echo &quot;success</pre><p>Change access rights with chmod 700 build.sh and test with ./build.sh to see if everything works fine.</p><p>Once this step is ready what is left is to have GitLab to call it each time code on develop branch is pushed. Here is and example .gitlab-ci.yaml file</p><pre>image: epcallan/php7-testing-phpunit:7.1-phpunit5</pre><pre>deploy_stage:<br>  stage: deploy<br>  variables:<br>    GIT_STRATEGY: none<br>  environment:<br>    name: stage<br>    url: <a href="http://mbps.qunabu.com/">http://helloworld.qunabu.com/</a><br>  before_script:<br>  - &#39;which ssh-agent || ( apt-get update -y &amp;&amp; apt-get install openssh-client -y )&#39;<br>  - eval $(ssh-agent -s)<br>  - ssh-add &lt;(echo &quot;$SSH_PRIVATE_KEY&quot;)<br>  - mkdir -p ~/.ssh<br>  - echo -e &quot;Host *\n\tStrictHostKeyChecking no\n\n&quot; &gt; ~/.ssh/config</pre><pre>script:<br>  - echo &quot;Deploy to staging server&quot;<br>  - ssh qunabu@qunabu.webfactional.com &#39;exec /home/qunabu/<a href="http://mbps.qunabu.com/">helloworld</a>/mbps/build.sh&#39;</pre><pre>  only:<br>  - develop</pre><p>Here is example from Gitlab console of successful build.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*puf8ojNW3YBJW45Wx20uUw.png" /></figure><h3>Resources</h3><ul><li><a href="https://www.drupal.org/docs/8/themes/barrio/creating-a-custom-barrio-sub-theme">Creating a custom Barrio sub-theme</a></li><li><a href="https://drupal-up.com/blog/installing-drupal-8-help-composer-and-docker">Installing Drupal 8 with the help of composer and Docker</a></li><li><a href="https://github.com/qunabucom/drupal-composer-mix/tree/develop">All the files from this post on github</a></li><li><a href="https://laravel.com/docs/5.7/mix">Laravel mix documentation</a></li><li><a href="https://docs.gitlab.com/ee/ci/ssh_keys/">Using SSH keys with GitLab CI/CD</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=754b1ccdf3ec" width="1" height="1" alt=""><hr><p><a href="https://medium.com/qunabu-interactive/drupal-8-docker-composer-bootstrap-laravel-mix-boilerplate-ci-on-gitlab-754b1ccdf3ec">Drupal 8. Docker, composer, bootstrap, laravel-mix boilerplate. CI on GitLab</a> was originally published in <a href="https://medium.com/qunabu-interactive">Escolasoft</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to upgrade to latest Gitlab from version less then 10.8]]></title>
            <link>https://medium.com/qunabu-interactive/how-to-upgrade-to-latest-gitlab-from-version-less-then-10-8-47a0b261edd1?source=rss-684cabb8f247------2</link>
            <guid isPermaLink="false">https://medium.com/p/47a0b261edd1</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[gitlab]]></category>
            <category><![CDATA[upgrade]]></category>
            <category><![CDATA[ubuntu]]></category>
            <dc:creator><![CDATA[Mateusz Wojczal]]></dc:creator>
            <pubDate>Tue, 16 Oct 2018 19:33:19 GMT</pubDate>
            <atom:updated>2018-10-16T19:33:19.756Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve come across issue when i wanted upgrade Gitlab CE from 10.5 to latest 11.X stable version. I’m using Ubuntu on my hosting machine, on the official documentation of GL says that you should run command</p><p>sudo apt-get update &amp;&amp; sudo apt-get install gitlab-ce</p><p>which should be just enough, yet the installer returns that you should upgrade to 10.8 in first place. I’m writing this post because I couldn’t find this tutorial anywhere.</p><p>Like most of similar tasks in Linux this is quite simple. You need to upgrate package manager with sudo apt-get update and then find last 10.8 available to your system with command</p><p>apt list -a gitlab-ce</p><p>then you need to find latest 10.8 version for your system and install this with</p><p>sudo apt-get install gitlab-ce=10.8.7-ce.0</p><p>where 10.8.7-ce.0 is the latest 10.8 version for Ubuntu at the moment of creation of this post.</p><p>Once this is ready you can run</p><p>sudo apt-get install gitlab-ce</p><p>to get the latest GitlabCE.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=47a0b261edd1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/qunabu-interactive/how-to-upgrade-to-latest-gitlab-from-version-less-then-10-8-47a0b261edd1">How to upgrade to latest Gitlab from version less then 10.8</a> was originally published in <a href="https://medium.com/qunabu-interactive">Escolasoft</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tuszama Case Study. Meteor.js app]]></title>
            <link>https://medium.com/qunabu-interactive/tuszama-case-study-meteor-js-app-7749d9eaeeda?source=rss-684cabb8f247------2</link>
            <guid isPermaLink="false">https://medium.com/p/7749d9eaeeda</guid>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[cordova]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[meteor]]></category>
            <category><![CDATA[app-development]]></category>
            <dc:creator><![CDATA[Mateusz Wojczal]]></dc:creator>
            <pubDate>Tue, 02 Oct 2018 07:56:33 GMT</pubDate>
            <atom:updated>2018-10-02T07:56:33.250Z</atom:updated>
            <content:encoded><![CDATA[<iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FrBZ0Fhby2zw%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DrBZ0Fhby2zw&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FrBZ0Fhby2zw%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/34a0e734e5db8de55276917672a75551/href">https://medium.com/media/34a0e734e5db8de55276917672a75551/href</a></iframe><p>Around 2014 polish government decided that there is too much junk food in schools, so their voted to ban selling it in small shops inside school buildings. As the idea was nobile and right, the result was that most of those shop had to close their business, since they lived from selling donuts rather than apples. The final outcome was they could not buy any food inside school at all.</p><p>Tuszama is an web and mobile app that meets the needs of those hungry students — it allows pupils in high schools to order food at their grand break. Whole process of ordering is straight forward — all you need is to:</p><ol><li>Create an account</li><li>Select your city</li><li>Select your school</li><li>Order available food</li><li>Collect food on grand break between lessons.</li></ol><p>There are few rules in the application</p><ul><li><strong>Client</strong> — student that orders food<br>Either by paying for each food separately<br>or by purchasing prepaid virtual wallet currency</li><li><strong>Provider</strong> — a food provider that have access to its panel responsible for:<br>- Management of food menu, managing the dishes<br>- Management of availability of the food for current day<br>- Getting instant notifications of the orders<br>- Getting daily PDF reports which are printed for provider chef and delivery driver.</li><li><strong>Administrator<br>- </strong>Manages whole process eg. new schools and providers</li></ul><h3>Business process. Tuszamas unique idea.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/316/1*n18cVGuPvx6XABbR_5XFpg.png" /><figcaption>When ordering food in Tuszama you have limited time.</figcaption></figure><p>Business process was quite different then standard food ordering. First pitfall is that each school has a big break different time, starting from 10 am to 12.30 pm. Food must be order at least one hour before this occurs — provider needs time to prepare exact amount of dishes and to deliver it on time. The other bottleneck was delivering, during the break there is no time to give each dish to particular pupil. Provider leaves all the dishes signed with username from the application and kids only collect their food. Here is an example movie how does it work.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FZMVAq2JRw48%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DZMVAq2JRw48&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FZMVAq2JRw48%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/50bd014bf06b0b46b300feaa6567dffa/href">https://medium.com/media/50bd014bf06b0b46b300feaa6567dffa/href</a></iframe><p>From technical point of view we have described the process in UML diagrams below.</p><h3>The objective</h3><p>We were commissioned to do the following:</p><ul><li>Advise the whole idea of the application. Define the pitfalls and bottlenecks</li><li>Define business process</li><li>Design whole corporate identity.</li><li>Create the minimum viable product (MVP) with just enough features to satisfy early customers, and to provide feedback for future product development.</li><li>Validate the idea and consult future steps</li><li>Maintain the application and add additional features</li></ul><h3>Implementation</h3><h4>Technology. Meteor.js</h4><p>The main feature of the app is that is had to work in real time, the time that app is working 90% is between 7am and 11am — when clients order the food. We decided that meteor.js would be perfect selection of technology for this task.</p><p><strong>Why meteor.js ?</strong></p><ul><li>Full stack JavaScript (JS) framework Javascript for both front-end and back-end in the same code base</li><li>Reactive programming out of the box</li><li>Thousands of npm packages</li><li>Lots of magic, syntactic sugar, cli tools, etc</li><li>Meteor official support for blaze (subset of handlebars), React and Angular.</li><li>Easy to learn, ability to build prototypes right away without too much effort</li><li>Build in Cordova support.</li></ul><h3>Initial documentation</h3><p>First we defined the business process in forms of text documentation and UML diagrams. After that we knew exactly what the app was suppose to do.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jbnLge3tmS7_SBir" /><figcaption>UML diagrams for Tuszama proceses</figcaption></figure><h3>Design process. UX and visuals.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ev63_ARP56CYV_9A" /><figcaption>Microcopy. Character example. Dark background with orange and white. Display typography</figcaption></figure><p>Secondly we went though UX process — creation of persons, making the prototypes and mockups. Once this was done, we passed whole documentation to the graphic designer.</p><p>Next step was to design a logo, select main colors, fonts, whole visual impression of the brand — that were dark backgrounds, orange text and display typography. We tried to get the impression that this is high school pupils app. We used microcopy a lot. Illustrator provided few characters we used for the whole design.</p><h3>Programming</h3><p>After about 2 months of intense programming in Scrum methodology and few weeks of testing we had application working. This was our first bigger project in meteor.js so we had to learn a lot which was harder then now — back in those days meteor.js community was not as big as now. It was delivered on time — just at the right moment when school starts in September 2015. The app was ready to validate the idea for few schools in Tricity area.</p><p>It features:</p><ul><li>One Javascript code es6 for backend and frontend</li><li>Continuous Integration features</li><li>Production application build from master git branch</li><li>Staging server build from `develop` git branch</li><li>Unit test run on each feature branch</li><li>Kadria instance to measure the app performance</li><li>Daily PDF reports for providers</li><li>Custom PDF and CSV reports for given criteria exported in real time.</li><li>D3 statistical diagrams</li><li>Cron email for providers. Email is sent one minute after order deadline</li><li>Three types of privileges — administrators, providers and clients</li><li>Daily backups with strong password send to client</li><li>Google Maps API address verification</li><li>Virtual wallet</li><li>Sophisticated order process based on each school and provider specific deadline</li><li>E-payments (based on Przelewy24)</li><li>Codrova iOS and Android app.</li></ul><h3>Environment</h3><ul><li>Deployment process is based on gitlab with its Continuous Integration features. I’ve written the whole article how this was achieved — see resources section at the end of the article.</li><li>Git flow for collaboration and scaling the development team.</li><li>The application use Digital Ocean Ubuntu machine.</li><li>We use own Kadria instance to measure the app. To see how to install own Kadira see resources section of this article.</li></ul><h3>F***up. (yep we’re not perfect)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mj1fuzmfYaQNt_75JVg-4A.png" /><figcaption>Performance measurement example from Kadira dashboard</figcaption></figure><p>Those were really hard moments for us — one day everything just exploded. Server CPU resources were higher than 100%, app was not responding even when we brought additional cores and memory. Client was losing money and reputation so we had to spend few days and nights on debugging and fixing. After all we fixed the bug <em>(too much data processed at once from MongoDB, badly implemented pagination, etc)</em> and right now we believe that the app is scaling perfectly.</p><p>From this lesson we know that except of unit test, stress tests are essential as well. Kadria was really helpful to fix this. Here I want to thank Sebastian, developer I found on LinkedIn, who helped me a lot that time. This is what the client said about this in our Clutch review.</p><blockquote>What did you find most impressive about them?</blockquote><blockquote>We had a crisis with our database about a year ago. Qunabu sorted it out and now everything works properly.</blockquote><h3>Mobile App.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aohEOpIhyM6YoxawFxccKQ.png" /><figcaption>Cordova mobile app on my Huawei smartphone</figcaption></figure><p>After two years of successful running client decided he want to introduce this as mobile app in addition to web version. Fortunately this was quite easy to achieve since meteor.js has build-in Cordova support. After several weeks of programming we’re able to push the prototype to Google Play and Apple App store. Apple had problem with payments and whole business process but after arranging the call with their validating team — we described how it works and they have passed it to the store. Since then its available to download.</p><h3>Outcome.</h3><p>For the moment of creating this article Tuszama application —</p><ul><li>Covers <strong>seven main cities</strong> in Poland</li><li><strong>17 providers</strong> delivers food</li><li>Pupils can order food in 46 schools</li><li>There are <strong>4400 registered users</strong></li><li>More than <strong>19000 orders</strong> were processed</li></ul><h3>Future.</h3><p>We’re still working on this project continuously improve it features. We work in Time &amp; Material for Tuszama — we talk on Slack channel, we estimate task in Redmine and incessantly improving application.</p><h3>Layouts.</h3><p>Below are some random layout screen shots from web version of application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3Wnr-SRP7IFKeTOQ" /><figcaption>Tuszama various layouts</figcaption></figure><h3>Our review from the client.</h3><p>We got really great review from the client, who gave it on clutch service.</p><p><strong>What evidence can you share that demonstrates the impact of the engagement?</strong></p><blockquote>We have around 5,000 customers and we’ve received around 18,000 orders in the last two years.</blockquote><p><strong>How did Qunabu Interactive perform from a project management standpoint?</strong></p><blockquote>My investor suggested switching our provider for website work, but I told him that even though Qunabu Interactive may give longer estimates than other companies, their delivery is fine. Other companies will promise to deliver in one or two weeks, but they never do. I prefer to work with someone who gives me realistic timelines. If Mateusz tells me that something will take two weeks, it will.</blockquote><h3>Resources</h3><ul><li><a href="https://medium.com/qunabu-interactive/deploying-secure-meteor-application-with-test-stage-and-landing-page-on-ubuntu-and-apache-including-9c625ef8d6c0">Deploying Secure Meteor Application with Test stage and Landing Page on Ubuntu and Apache including Continuous Integration deployment based on Gitlab. Part 1</a></li><li><a href="https://qunabu.com/work/tuszama">Tuszama on Qunabu Interactive</a></li><li><a href="https://clutch.co/profile/qunabu-interactive#review-594166">Tuszama owner review on Clutch</a></li><li><a href="https://medium.com/@foodfitnesscode/setting-up-kadira-on-a-ubuntu-16-04-server-part-1-a821cdddd1e6">Setting up Kadira on a Ubuntu 16.04 Server part 1</a> by <a href="https://medium.com/@foodfitnesscode?source=post_header_lockup">Michael Lazarski</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7749d9eaeeda" width="1" height="1" alt=""><hr><p><a href="https://medium.com/qunabu-interactive/tuszama-case-study-meteor-js-app-7749d9eaeeda">Tuszama Case Study. Meteor.js app</a> was originally published in <a href="https://medium.com/qunabu-interactive">Escolasoft</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Photo booth story. How programming is fun after work (during my wedding).]]></title>
            <link>https://medium.com/qunabu-interactive/photo-booth-story-how-programming-is-fun-after-work-during-my-wedding-64e38ed38419?source=rss-684cabb8f247------2</link>
            <guid isPermaLink="false">https://medium.com/p/64e38ed38419</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[raspberry-pi]]></category>
            <category><![CDATA[cnc]]></category>
            <category><![CDATA[photography]]></category>
            <category><![CDATA[dyi]]></category>
            <dc:creator><![CDATA[Mateusz Wojczal]]></dc:creator>
            <pubDate>Wed, 19 Sep 2018 08:56:47 GMT</pubDate>
            <atom:updated>2018-09-20T10:11:42.737Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7eHsUj9o2E6eMvPPs2p3ow.jpeg" /><figcaption>Almost ready photo booth in the garage.</figcaption></figure><p>Last week I had a wedding :) It was a great party but this is not a blog about entertainment. Since I’m very enthusiastic about DIY and Raspberry i thought — why not build a self made photo booth that instead of instantly printing images is uploading them on special new instagram account that everybody would have access to. I talked with my brother Rafal and we decided that it shouldn’t be a big deal. So this is how we have done it.</p><p>First of all was to decide the hardware parts. I had an old SLR Camera Nikon d80. After few tests with USB and its PTP mode I’ve found out about libgphoto2 library and its capabilities. D80 is quite old and have no live preview, so this was the only pitfall. Anyway I decided that without preview final pictures would be even funnier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/425/1*IQIDE7lR-GlQJhGd8eOGDA.jpeg" /><figcaption>d80 SLR (picture from amazon)</figcaption></figure><p>Below is the quick relation of garage battlefield.</p><iframe src="https://cdn.embedly.com/widgets/media.html?type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=instagram&amp;url=https%3A//www.instagram.com/p/BmMPg3ujWxy/&amp;image=https%3A//i.embed.ly/1/image%3Furl%3Dhttps%253A%252F%252Fscontent-iad3-1.cdninstagram.com%252Fvp%252F79b3e0b0c1e71906b9947b0a5f9dc956%252F5C29196B%252Ft51.2885-15%252Fe35%252F37857384_447825652287766_8401225106382127104_n.jpg%26key%3Da19fcc184b9711e1b4764040d3dc5c07" width="1080" height="1080" frameborder="0" scrolling="no"><a href="https://medium.com/media/40b356e5996cff113fb2ab42cfffb90b/href">https://medium.com/media/40b356e5996cff113fb2ab42cfffb90b/href</a></iframe><h3>Ingredients :)</h3><p>So final list of hardware parts where</p><ul><li>D80 SLR</li><li>LED light panel</li><li>Some wires (power, usb, gpio, hdmi, etc)</li><li>Soldered battery connection with external Power Supply</li><li>Big button to take pictures</li><li>Rasperry PI with brand new NOOBS</li><li>Wooden box</li><li>Wooden parts to hold everything together</li><li>Square LCD display with HDMI</li><li>Tripod</li></ul><h3>Hardware</h3><p>In terms of putting in all together it wasn’t hard for some parts — a power for LED panel, LCD display and raspberry PI, but was for the others. Since D80 is quite old, addons like permanent power supply was almost impossible to get, unachievable in such short notice. Rafał had to solder the battery connection with external power supply based on diagrams from google images. Last piece of art was to connect button through Raspberry GPIO and to put it all together so that it does not fall apart during the party. Everything was inside big wooden box pictured below.</p><p>Front panel was cut with CNC machine with written instruction and bespoke holes for SLR camera, button and LCD display.</p><h3>Software</h3><p>I thought that I wasn’t a first person that came with that idea, so i search the open source community i came across great python script by Balthasar Reuter. I had to amend some logic and graphic layout, but this wasn’t a hard task, much harder was that i had never ever used python before.</p><h3>Instagram script with Paulo Coelho quotes.</h3><p>Uploading picture thought Instargram API is not allowed. For commercial project i wouldn’t never ever try to bypass this restriction, yet this was just one day party personal event. There are lot of hacky script in github that did this so I’ve copy the method from one of them and added some funny functionality — each uploaded photo was having a caption with random quote of Paulo Coelho. You can get all the quotes from my github repository (linked below).</p><h3>Watch script</h3><p>Python photobooth and uploading scripts were separated so i needed a simplest way to synchronize them. I’ve come with idea</p><ul><li>Once picture is done its being placed in <em>to_upload</em> folder</li><li>When watch script finds a first file in <em>to_upload</em> folder it moves it to <em>uploading</em> folder and starts putting it on instagram</li><li>Once picture is uploaded is was moved to <em>uploaded</em> folder</li></ul><p>This was part of php instagram script now i needed a way to launch this script every time a new file is being put in “to_upload” folder. Without any dependencies following python script is doing the job.</p><pre>#!/usr/bin/env python</pre><pre>import subprocess<br>import time</pre><pre>folder = &quot;to_upload&quot;<br>application = &quot;php insta.php&quot;</pre><pre>def get_drlist():<br>    return subprocess.check_output([&quot;ls&quot;, folder]).decode(&#39;utf-8&#39;).strip().split(&quot;\n&quot;)</pre><pre>while True:<br>    drlist1 = get_drlist()<br>    time.sleep(2)<br>    drlist2 = get_drlist()<br>    for file in [f for f in drlist2 if not f in drlist1]:<br>            command = application+&quot; &#39;&quot;+folder+&quot;/&quot;+file+&quot;&#39;&quot;<br>            subprocess.Popen([&quot;/bin/bash&quot;, &quot;-c&quot;, command])</pre><h3>Startup script.</h3><p>This was quite a surprise but Raspbian wasn’t respecting some standard techniques Iuse for default Linux startup script like services or putting shell script in init.d folder. In te resources section I’m linking an article “Run a Program On Your Raspberry Pi At Startup” yet none of this 5 methods actually worked on my system. What did worked in amending ~/.config/lxsession/LXDE-pi file. There I had to put commands to run two python scripts</p><ol><li>photobooth script</li><li>watch script</li></ol><h3>Final Result</h3><iframe src="https://cdn.embedly.com/widgets/media.html?type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=instagram&amp;url=https%3A//www.instagram.com/p/Bn5r5VkBPHR/&amp;image=https%3A//i.embed.ly/1/image%3Furl%3Dhttps%253A%252F%252Fscontent-iad3-1.cdninstagram.com%252Fvp%252F54d8bc12c8304aa5c31d2a5ab717eed5%252F5BA471E6%252Ft51.2885-15%252Fsh0.08%252Fe35%252Fs640x640%252F40639917_465781333929922_4632533576896679676_n.jpg%26key%3Da19fcc184b9711e1b4764040d3dc5c07" width="640" height="640" frameborder="0" scrolling="no"><a href="https://medium.com/media/da801abdccdaaf636727f836052bcf7e/href">https://medium.com/media/da801abdccdaaf636727f836052bcf7e/href</a></iframe><h3>Sample pictures</h3><p>Below are sample pictures taken during the wedding. Note the quotes :D</p><iframe src="https://cdn.embedly.com/widgets/media.html?type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=instagram&amp;url=https%3A//www.instagram.com/p/Bmln8NMlKT-/&amp;image=https%3A//i.embed.ly/1/image%3Furl%3Dhttps%253A%252F%252Fscontent-iad3-1.cdninstagram.com%252Fvp%252F110faa45a12be7e32977a59c5b60684a%252F5C264D47%252Ft51.2885-15%252Fsh0.08%252Fe35%252Fs640x640%252F38191581_272934599970980_7794135859959169024_n.jpg%26key%3Da19fcc184b9711e1b4764040d3dc5c07" width="640" height="432" frameborder="0" scrolling="no"><a href="https://medium.com/media/6f37454d1c526d8b49a54b0244b2c3fa/href">https://medium.com/media/6f37454d1c526d8b49a54b0244b2c3fa/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=instagram&amp;url=https%3A//www.instagram.com/p/BmlmVgFlAYA/&amp;image=https%3A//i.embed.ly/1/image%3Furl%3Dhttps%253A%252F%252Fscontent-iad3-1.cdninstagram.com%252Fvp%252Ff2fa0c806a3e00e2ff744623cdddc77f%252F5C200344%252Ft51.2885-15%252Fsh0.08%252Fe35%252Fs640x640%252F39053283_2207999625937592_376849218054127616_n.jpg%26key%3Da19fcc184b9711e1b4764040d3dc5c07" width="640" height="432" frameborder="0" scrolling="no"><a href="https://medium.com/media/6020d6ed138f76bdfa8b898e2ee1c0aa/href">https://medium.com/media/6020d6ed138f76bdfa8b898e2ee1c0aa/href</a></iframe><h3>Resources</h3><ol><li><a href="https://github.com/reuterbal/photobooth">Python photobooth script by Balthasar Reuter</a></li><li><a href="https://www.dexterindustries.com/howto/run-a-program-on-your-raspberry-pi-at-startup/">Run a Program On Your Raspberry Pi At Startup</a></li><li><a href="https://raspberrypi.stackexchange.com/questions/8734/execute-script-on-start-up">Raspberry PI Forum Exchange thread “Execute script on start-up”</a></li><li><a href="https://github.com/nikos90/instagram_upload">Example PHP Instagram upload script</a></li><li><a href="https://www.raspberrypi.org/downloads/noobs/">Raspery PI with brand new NOOBS</a></li><li><a href="https://github.com/qunabu/photobooth/">All my scripts in github repository</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=64e38ed38419" width="1" height="1" alt=""><hr><p><a href="https://medium.com/qunabu-interactive/photo-booth-story-how-programming-is-fun-after-work-during-my-wedding-64e38ed38419">Photo booth story. How programming is fun after work (during my wedding).</a> was originally published in <a href="https://medium.com/qunabu-interactive">Escolasoft</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>